Warning, /frameworks/syntax-highlighting/autotests/input/devicedetect.vcl is written in an unsupported language. File is not indexed.
0001 # 0002 # Copyright (c) 2016-2018 Varnish Cache project 0003 # Copyright (c) 2012-2016 Varnish Software AS 0004 # 0005 # SPDX-License-Identifier: BSD-2-Clause 0006 # 0007 # Redistribution and use in source and binary forms, with or without 0008 # modification, are permitted provided that the following conditions 0009 # are met: 0010 # 1. Redistributions of source code must retain the above copyright 0011 # notice, this list of conditions and the following disclaimer. 0012 # 2. Redistributions in binary form must reproduce the above copyright 0013 # notice, this list of conditions and the following disclaimer in the 0014 # documentation and/or other materials provided with the distribution. 0015 # 0016 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 0017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0018 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0019 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 0020 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 0021 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 0022 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 0023 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 0024 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 0025 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 0026 # SUCH DAMAGE. 0027 # 0028 # detectdevice.vcl - regex based device detection for Varnish 0029 # https://github.com/varnishcache/varnish-devicedetect/ 0030 # 0031 # Original author: Lasse Karstensen <lkarsten@varnish-software.com> 0032 0033 sub devicedetect { 0034 unset req.http.X-UA-Device; 0035 set req.http.X-UA-Device = "pc"; 0036 0037 # Handle that a cookie may override the detection alltogether. 0038 if (req.http.Cookie ~ "(?i)X-UA-Device-force") { 0039 /* ;?? means zero or one ;, non-greedy to match the first. */ 0040 set req.http.X-UA-Device = regsub(req.http.Cookie, "(?i).*X-UA-Device-force=([^;]+);??.*", "\1"); 0041 /* Clean up our mess in the cookie header */ 0042 set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *X-UA-Device-force=[^;]+;? *", "\1"); 0043 /* If the cookie header is now empty, or just whitespace, unset it. */ 0044 if (req.http.Cookie ~ "^ *$") { unset req.http.Cookie; } 0045 } else { 0046 if (req.http.User-Agent ~ "\(compatible; Googlebot-Mobile/2.1; \+http://www.google.com/bot.html\)" || 0047 (req.http.User-Agent ~ "(Android|iPhone)" && req.http.User-Agent ~ "\(compatible.?; Googlebot/2.1.?; \+http://www.google.com/bot.html") || 0048 (req.http.User-Agent ~ "(iPhone|Windows Phone)" && req.http.User-Agent ~ "\(compatible; bingbot/2.0; \+http://www.bing.com/bingbot.htm")) { 0049 set req.http.X-UA-Device = "mobile-bot"; } 0050 elsif (req.http.User-Agent ~ "(?i)(ads|google|bing|msn|yandex|baidu|ro|career|seznam|)bot" || 0051 req.http.User-Agent ~ "(?i)(baidu|jike|symantec)spider" || 0052 req.http.User-Agent ~ "(?i)pingdom" || 0053 req.http.User-Agent ~ "(?i)facebookexternalhit" || 0054 req.http.User-Agent ~ "(?i)scanner" || 0055 req.http.User-Agent ~ "(?i)slurp" || 0056 req.http.User-Agent ~ "(?i)(web)crawler") { 0057 set req.http.X-UA-Device = "bot"; } 0058 elsif (req.http.User-Agent ~ "(?i)ipad") { set req.http.X-UA-Device = "tablet-ipad"; } 0059 elsif (req.http.User-Agent ~ "(?i)ip(hone|od)") { set req.http.X-UA-Device = "mobile-iphone"; } 0060 /* how do we differ between an android phone and an android tablet? 0061 http://stackoverflow.com/questions/5341637/how-do-detect-android-tablets-in-general-useragent */ 0062 elsif (req.http.User-Agent ~ "(?i)android.*(mobile|mini)") { set req.http.X-UA-Device = "mobile-android"; } 0063 // android 3/honeycomb was just about tablet-only, and any phones will probably handle a bigger page layout. 0064 elsif (req.http.User-Agent ~ "(?i)android 3") { set req.http.X-UA-Device = "tablet-android"; } 0065 /* Opera Mobile */ 0066 elsif (req.http.User-Agent ~ "Opera Mobi") { set req.http.X-UA-Device = "mobile-smartphone"; } 0067 // May very well give false positives towards android tablets. Suggestions welcome. 0068 elsif (req.http.User-Agent ~ "(?i)android") { set req.http.X-UA-Device = "tablet-android"; } 0069 elsif (req.http.User-Agent ~ "PlayBook; U; RIM Tablet") { set req.http.X-UA-Device = "tablet-rim"; } 0070 elsif (req.http.User-Agent ~ "hp-tablet.*TouchPad") { set req.http.X-UA-Device = "tablet-hp"; } 0071 elsif (req.http.User-Agent ~ "Kindle/3") { set req.http.X-UA-Device = "tablet-kindle"; } 0072 elsif (req.http.User-Agent ~ "Touch.+Tablet PC" || 0073 req.http.User-Agent ~ "Windows NT [0-9.]+; ARM;" ) { 0074 set req.http.X-UA-Device = "tablet-microsoft"; 0075 } 0076 elsif (req.http.User-Agent ~ "Mobile.+Firefox") { set req.http.X-UA-Device = "mobile-firefoxos"; } 0077 elsif (req.http.User-Agent ~ "^HTC" || 0078 req.http.User-Agent ~ "Fennec" || 0079 req.http.User-Agent ~ "IEMobile" || 0080 req.http.User-Agent ~ "BlackBerry" || 0081 req.http.User-Agent ~ "BB10.*Mobile" || 0082 req.http.User-Agent ~ "GT-.*Build/GINGERBREAD" || 0083 req.http.User-Agent ~ "SymbianOS.*AppleWebKit") { 0084 set req.http.X-UA-Device = "mobile-smartphone"; 0085 } 0086 elsif (req.http.User-Agent ~ "(?i)symbian" || 0087 req.http.User-Agent ~ "(?i)^sonyericsson" || 0088 req.http.User-Agent ~ "(?i)^nokia" || 0089 req.http.User-Agent ~ "(?i)^samsung" || 0090 req.http.User-Agent ~ "(?i)^lg" || 0091 req.http.User-Agent ~ "(?i)bada" || 0092 req.http.User-Agent ~ "(?i)blazer" || 0093 req.http.User-Agent ~ "(?i)cellphone" || 0094 req.http.User-Agent ~ "(?i)iemobile" || 0095 req.http.User-Agent ~ "(?i)midp-2.0" || 0096 req.http.User-Agent ~ "(?i)u990" || 0097 req.http.User-Agent ~ "(?i)netfront" || 0098 req.http.User-Agent ~ "(?i)opera mini" || 0099 req.http.User-Agent ~ "(?i)palm" || 0100 req.http.User-Agent ~ "(?i)nintendo wii" || 0101 req.http.User-Agent ~ "(?i)playstation portable" || 0102 req.http.User-Agent ~ "(?i)portalmmm" || 0103 req.http.User-Agent ~ "(?i)proxinet" || 0104 req.http.User-Agent ~ "(?i)windows\ ?ce" || 0105 req.http.User-Agent ~ "(?i)winwap" || 0106 req.http.User-Agent ~ "(?i)eudoraweb" || 0107 req.http.User-Agent ~ "(?i)htc" || 0108 req.http.User-Agent ~ "(?i)240x320" || 0109 req.http.User-Agent ~ "(?i)avantgo") { 0110 set req.http.X-UA-Device = "mobile-generic"; 0111 } 0112 } 0113 }