Skip to content

Instantly share code, notes, and snippets.

@sunnyone
Last active April 7, 2017 04:47
Show Gist options
  • Save sunnyone/ad655d2fe50349ced1c4 to your computer and use it in GitHub Desktop.
Save sunnyone/ad655d2fe50349ced1c4 to your computer and use it in GitHub Desktop.
Fiddler script to replace 127.0.0.1/localhost
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