IGN VCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub vcl_recv { | |
#FASTLY recv | |
# If geo_override header is supplied use that instead of built in geoip library. For testing. | |
if ( req.http.geo_override ) { | |
set req.http.X-Geo-Country = req.http.geo_override; | |
} else { | |
set req.http.X-Geo-Country = geoip.country_code; | |
} | |
if ( req.http.Cookie ~ "mobile_redirect" ) { | |
set req.http.IGN_COOKIE = req.http.IGN_COOKIE regsub(req.http.Cookie,"^.*[&?]mobile_redirect=([^&]+).*", "\1"); | |
} | |
if ( req.http.Cookie ~ "i18n-ccpref" ) { | |
set req.http.IGN_COOKIE = regsub(req.http.Cookie,"^.*[&?]i18n-ccpref=([^&]+).*", "\1"); | |
} | |
if ( req.url ~ "setccpref" ) { | |
set req.http.i18n-ccpref = regsub(req.url,"^.*[&?]setccpref=([^&]+).*", "\1"); | |
} | |
# No redirects | |
if ( req.url ~ "^/videos/\d+/\d+/\d+/[^.]" || req.url ~ "^/boards" ) { | |
} else { | |
if ( req.http.X-Geo-Country ~ "FR|GB|PL|UK" ) { | |
set req.http.region = "uk"; | |
} else if ( req.http.X-Geo-Country ~ "AU|NZ" ) { | |
set req.http.region = "au"; | |
} else if ( req.http.X-Geo-Country == "IE" ) { | |
set req.http.region = "ie"; | |
} else if ( req.http.X-Geo-Country == "CA" ) { | |
set req.http.region = "ca"; | |
} else if ( req.http.X-Geo-Country ~ "PH|MY|SG|ID|CN|HK|TW|TH|VN" ) { | |
set req.http.region = "ap"; | |
} else if ( req.http.X-Geo-Country == "FI" ) { | |
set req.http.region = "fi"; | |
} else if ( req.http.X-Geo-Country ~ "AE|BH|DZ|EG|IQ|JO|KW|LB|MA|OM|PK|PS|QA|SA|SY|TN" ) { | |
set req.http.region = "me"; | |
} else if ( req.http.X-Geo-Country == "SE" ) { | |
set req.http.region = "se"; | |
} else if ( req.http.X-Geo-Country ~ "NL|BE|LU" ) { | |
set req.http.region = "nl"; | |
} else if ( req.http.X-Geo-Country ~ "IT|VA|SM" ) { | |
set req.http.region = "it"; | |
} else if ( req.http.X-Geo-Country ~ "AT|CH|DE" ) { | |
set req.http.region = "de"; | |
} else if ( req.http.X-Geo-Country == "DK" ) { | |
set req.http.region = "dk"; | |
} else if ( req.http.X-Geo-Country == "PT" ) { | |
set req.http.region = "pt"; | |
} else if ( req.http.X-Geo-Country ~ "GR|CY" ) { | |
set req.http.region = "gr"; | |
} else if ( req.http.X-Geo-Country == "ES" ) { | |
set req.http.region = "es"; | |
} else if ( req.http.X-Geo-Country ~ "RU|AM|UA|BY|KZ" ) { | |
set req.http.region = "ru"; | |
} else if ( req.http.X-Geo-Country == "NO" ) { | |
set req.http.region = "no"; | |
} else if ( req.http.X-Geo-Country == "TR" ) { | |
set req.http.region = "tr"; | |
} else if ( req.http.X-Geo-Country == "IN" ) { | |
set req.http.region = "in"; | |
} else if ( req.http.X-Geo-Country == "PR" ) { | |
set req.http.region = "pr"; | |
} else if ( req.http.X-Geo-Country == "CL" ) { | |
set req.http.region = "cl"; | |
} else if ( req.http.X-Geo-Country == "CO" ) { | |
set req.http.region = "co"; | |
} else if ( req.http.X-Geo-Country == "IL" ) { | |
set req.http.region = "il"; | |
} else if ( req.http.X-Geo-Country ~ "AR|BO|CR|DO|EC|SV|GT|HN|NI|PA|PY|PE|TT|UY|VE|MX" ) { | |
set req.http.region = "latam"; | |
} else if ( req.http.X-Geo-Country ~ "AO|BW|CD|ET|KE|LS|MG|MW|MU|MZ|NA|CG|SC|SZ|TZ|UG|ZA|ZM|ZW|NG" ) { | |
set req.http.region = "za"; | |
} | |
} | |
set req.http.X-Reverse-Proxy = "Fastly"; | |
# Strip off query arguments such as gclid, utm_medium etc. | |
# set req.url = regsuball(req.url, "(?:gclid|utm_campaign|utm_medium|utm_source|abthid)=[^&]*", ""); | |
# Pass these request paths | |
if ( req.url ~ "^/(support|face-off|private)" || req.url ~ "debug" || req.url ~ "^/.*/private" ) { | |
return(pass); | |
} else if ( req.url ~ "^/robots.txt" ) { | |
error 900 "Fastly Internal"; | |
} | |
if (req.request != "HEAD" && req.request != "GET" && req.request != "FASTLYPURGE") { | |
return(pass); | |
} | |
return(lookup); | |
} | |
sub vcl_fetch { | |
#FASTLY fetch | |
# Cache 404s for 10 minutes | |
if ( beresp.status == 404 ) { | |
set beresp.ttl = 10m; | |
set beresp.grace = 30m; | |
} | |
if ((beresp.status == 500 || beresp.status == 503) && req.restarts < 1 && (req.request == "GET" || req.request == "HEAD")) { | |
restart; | |
} | |
if(req.restarts > 0 ) { | |
set beresp.http.Fastly-Restarts = req.restarts; | |
} | |
if (beresp.http.Set-Cookie) { | |
set req.http.Fastly-Cachetype = "SETCOOKIE"; | |
return (pass); | |
} | |
if (beresp.http.Cache-Control ~ "private|no-cache") { | |
set req.http.Fastly-Cachetype = "PRIVATE"; | |
return (pass); | |
} | |
if (beresp.status == 500 || beresp.status == 503) { | |
set req.http.Fastly-Cachetype = "ERROR"; | |
set beresp.ttl = 1s; | |
set beresp.grace = 5s; | |
return (deliver); | |
} | |
if (beresp.http.Expires || beresp.http.Surrogate-Control ~ "max-age" || beresp.http.Cache-Control ~"(s-maxage|max-age)") { | |
# keep the ttl here | |
} else { | |
# apply the default ttl | |
set beresp.ttl = 15m; | |
} | |
return(deliver); | |
} | |
sub vcl_hit { | |
#FASTLY hit | |
if (!obj.cacheable) { | |
return(pass); | |
} | |
return(deliver); | |
} | |
sub vcl_miss { | |
#FASTLY miss | |
return(fetch); | |
} | |
sub vcl_deliver { | |
#FASTLY deliver | |
return(deliver); | |
} | |
sub vcl_error { | |
#FASTLY error | |
# Handle redirects | |
if (obj.status == 850) { | |
set obj.http.Location = obj.response; | |
set obj.status = 301; | |
return(deliver); | |
} | |
if (obj.status == 851) { | |
set obj.http.Location = obj.response; | |
set obj.status = 302; | |
return(deliver); | |
} | |
if (obj.status == 900 ) { | |
set obj.http.Content-Type = "text/plain"; | |
set obj.status = 200; | |
set obj.response = "OK"; | |
synthetic {"User-agent: * | |
Disallow: /_views/ | |
Disallow: /apiproxy | |
Disallow: /boards/search | |
Disallow: /debug | |
Disallow: /pokedex/search | |
Disallow: /search | |
Disallow: /stf/ | |
Disallow: /sugarfif.html | |
User-agent: Exabot | |
Disallow: / | |
User-agent: AhrefsBot | |
Disallow: / | |
User-agent: PiplBot | |
Disallow: / | |
Sitemap: http://www.ign.com/sitemap.xml | |
"}; | |
return(deliver); | |
} | |
} | |
sub vcl_pass { | |
#FASTLY pass | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment