fiddler: how to disable overwrite Header Host

bettermanlu picture bettermanlu · Aug 8, 2012 · Viewed 8.6k times · Source

When using Fiddler, it pops up an alert dialog.

Fiddler has detected a protocol violation in session #14.

The Request's Host header did not match the URL's host component.

URL Host:   proxy.music.pp.com
Header Host:    119.147.22.41

And it shows that Fiddler changed HTTP Header's host to "proxy.music.pp.com", is there any way to disable Fiddler changing it?

Answer

EricLaw picture EricLaw · Feb 13, 2013

From my book:

Swap the Host Header

When Fiddler gets a request whose URL doesn’t match its Host header, the original Host value is stored in the session flag X-Original-Host and then the Host value is replaced with the host parsed from the URL. The following script, placed inside your FiddlerScript's BeforeRequest function, reverses behavior by routing the request to the host specified by the original Host header.

if (oSession.BitFlags & SessionFlags.ProtocolViolationInRequest) 
{
  var sOverride = oSession["X-Original-Host"];
  if (!String.IsNullOrEmpty(sOverride)) 
  {
    oSession["X-overrideHost"] = sOverride;
    oSession["ui-backcolor"] = "yellow";

    // Be sure to bypass the gateway, otherwise overrideHost doesn't work
    oSession.bypassGateway = true;
  }
}