Commit 0e6ced86 authored by David Fifield's avatar David Fifield
Browse files

Clear Firefox's pre-set headers.

These include User-Agent, Accept, Accept-Language, and Accept-Encoding,
and don't do anything for us but make the requests larger.

With this removal, the header drops to about 162 bytes, saving 219 bytes
on top of the 32 in the previous commit, or about 50%.

https://trac.torproject.org/projects/tor/ticket/12778
parent 4812b9a8
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -212,6 +212,16 @@ MeekHTTPHelper.LocalConnectionHandler.prototype = {
        var uri = MeekHTTPHelper.ioService.newURI(req.url, null, null);
        var uri = MeekHTTPHelper.ioService.newURI(req.url, null, null);
        this.channel = MeekHTTPHelper.httpProtocolHandler.newProxiedChannel(uri, proxyInfo, 0, null)
        this.channel = MeekHTTPHelper.httpProtocolHandler.newProxiedChannel(uri, proxyInfo, 0, null)
            .QueryInterface(Components.interfaces.nsIHttpChannel);
            .QueryInterface(Components.interfaces.nsIHttpChannel);
        // Remove pre-set headers. Firefox's AddStandardRequestHeaders adds
        // User-Agent, Accept, Accept-Language, and Accept-Encoding, and perhaps
        // others. Just remove all of them.
        var headers = [];
        // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIHttpChannel#visitRequestHeaders%28%29
        // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIHttpHeaderVisitor
        this.channel.visitRequestHeaders({visitHeader: function(key, value) { headers.push(key); }})
        for (var i = 0; i < headers.length; i++)
            this.channel.setRequestHeader(headers[i], "", false);
        // Set our own headers.
        if (req.header !== undefined) {
        if (req.header !== undefined) {
            for (var key in req.header) {
            for (var key in req.header) {
                this.channel.setRequestHeader(key, req.header[key], false);
                this.channel.setRequestHeader(key, req.header[key], false);