File indexing completed on 2024-05-19 15:23:12

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