Created
March 19, 2017 00:00
-
-
Save jakub-g/a5a44092175f1fd2e1aa5fd80531f6d7 to your computer and use it in GitHub Desktop.
FiddlerScript: lint caching headers (to be put in OnPeekAtResponseHeaders)
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
static function checkForInvalidCachingHeaders(oSession: Session) { | |
// var _temp : int = 0; | |
// && !(int.TryParse(oSession.oResponse["Expires"], out _temp)) | |
if (oSession.oResponse.headers.Exists("Expires") | |
&& oSession.oResponse.headers.Exists("Date") | |
&& oSession.oResponse.headers.ExistsAndContains("Cache-Control", "max-age")) | |
{ | |
try { | |
var ageSeconds : Int64 = 0; | |
var ageHours : Int64 = 0; | |
if (oSession.oResponse.headers.Exists("Age")) { | |
ageSeconds = Int64.Parse(oSession.oResponse["Age"]); | |
ageHours = Convert.ToInt64(ageSeconds / 3600); | |
} | |
var expiresDiff : TimeSpan = DateTime.Parse(oSession.oResponse["Expires"]) - DateTime.Parse(oSession.oResponse["Date"]); | |
var expiresHours : Int64 = Convert.ToInt64((expiresDiff.TotalHours + ageHours)); | |
var cacheControl : String = oSession.oResponse["Cache-Control"]; | |
var match : System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(cacheControl, "max-age=([0-9]+)"); | |
var cacheControlSeconds : Int64 = Int64.Parse(match.Groups[1].Value); | |
var cacheControlHours : Int64 = Convert.ToInt64((cacheControlSeconds / 3600)); | |
if (expiresHours > 0 | |
&& cacheControlHours > 0 | |
&& expiresHours != cacheControlHours | |
&& (expiresHours > 1.2 * cacheControlHours || expiresHours < 0.8 * cacheControlHours) | |
) { | |
oSession["ui-backcolor"] = "purple"; | |
oSession["ui-color"] = "white"; | |
oSession["ui-Comments"] = "cacheControlHrs=" + cacheControlHours + "; expiresHrs=" + expiresHours; | |
oSession.RefreshUI(); | |
} | |
} catch(ex) { | |
oSession["ui-Comments"] = ex.ToString(); | |
} | |
} //endif invalid caching headers | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment