Advertisement
Guest User

device-detect

a guest
Mar 12th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. sub vcl_recv {
  2. if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf)$") {
  3. set req.http.X-Device = "NA";
  4. } else {
  5. call identify_device;
  6. }
  7. }
  8.  
  9. sub identify_device {
  10. if (req.http.User-Agent ~ "mobileapp" ) {
  11. set req.http.X-Device = "mobileapp";
  12. } else {
  13. set req.http.X-Device = "PC";
  14. }
  15. }
  16.  
  17. sub vcl_deliver {
  18. if (req.http.X-Device != "NA") {
  19. if (resp.http.Vary) {
  20. set resp.http.Vary = resp.http.Vary + "," + "User-Agent";
  21. } else {
  22. set resp.http.Vary = "User-Agent";
  23. }
  24. }
  25. }
  26.  
  27. sub vcl_hash {
  28. hash_data(req.http.X-Device);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement