[tor-commits] [meek/master] Clear Firefox's pre-set headers.

dcf at torproject.org dcf at torproject.org
Fri Dec 26 23:08:27 UTC 2014


commit 0e6ced86880b54f57a80b34d7f1b32a0eaa33b48
Author: David Fifield <david at bamsoftware.com>
Date:   Fri Dec 26 00:32:10 2014 -0800

    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
---
 firefox/components/main.js |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/firefox/components/main.js b/firefox/components/main.js
index 6e3b0e0..9b8e980 100644
--- a/firefox/components/main.js
+++ b/firefox/components/main.js
@@ -212,6 +212,16 @@ MeekHTTPHelper.LocalConnectionHandler.prototype = {
         var uri = MeekHTTPHelper.ioService.newURI(req.url, null, null);
         this.channel = MeekHTTPHelper.httpProtocolHandler.newProxiedChannel(uri, proxyInfo, 0, null)
             .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) {
             for (var key in req.header) {
                 this.channel.setRequestHeader(key, req.header[key], false);



More information about the tor-commits mailing list