Newer Apache configurations reportedly do not require this hack. Due to the broken patches of bug 542222 I cannot find the history of this method.
Introduced here http://hg.mozilla.org/mozilla-central/diff/1238046c4cce/netwerk/protocol/http/src/nsHttpChannel.cpp. Why do you believe we need to remove it?
Luckily, this is actually CVS-era code. ;) This was added in bug 35956. In particular, see bug 35956 comment 64.
It seems bug comment 120 goes to the heart of the issue. Honza, we should either get our non-standard behavior in the network layer standardized, or remove it. Otherwise Servo will have a hard time competing with us.
Note that specifically for the save-to-file behavior what we actually do is completely ignore the Content-Type when deciding whether to decode. We just compare the URI filename extension, if any, to the Content-Encoding. If the Content-Encoding matches the filename extension, we don't undo the content encoding; otherwise we undo it. So if you send: Content-Type: text/html Content-Encoding: gzip and the filename is "foo.html" then we'll gunzip when saving, but if it's "foo.html.gz" then we won't.
Any chance of getting telemetry on how often this actually happens?