Last active
April 7, 2017 04:47
-
-
Save sunnyone/ad655d2fe50349ced1c4 to your computer and use it in GitHub Desktop.
Fiddler script to replace 127.0.0.1/localhost
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 replaceLocalHost(str) { | |
str = str.replace(/\/\/127\.0\.0\.1/gi, "//ipv4.fiddler"); | |
str = str.replace(/\/\/localhost/gi, "//localhost.fiddler"); | |
return str; | |
} | |
static function OnBeforeResponse(oSession: Session) { | |
if (oSession.HostnameIs("localhost.fiddler") || oSession.HostnameIs("ipv4.fiddler")) { | |
if (oSession.oResponse.headers.Exists("Location")) { | |
var location = oSession.oResponse.headers["Location"]; | |
oSession.oResponse.headers["Location"] = replaceLocalHost(location); | |
} | |
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")) { | |
oSession.utilDecodeResponse(); | |
var body = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes); | |
oSession.utilSetResponseBody(replaceLocalHost(body)); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment