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