Bug 1467523 - Followup fix for case insensitive header name check. r=aswan,robwu, a=RyanVM
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 10 Oct 2018 16:23:46 -0400
changeset 490269 f439e5f9e3d3
parent 490268 66ab8622488c
child 490270 dc0694bc87c1
push id9969
push userryanvm@gmail.com
push dateThu, 11 Oct 2018 17:41:24 +0000
treeherdermozilla-beta@f439e5f9e3d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, robwu, RyanVM
bugs1467523
milestone63.0
Bug 1467523 - Followup fix for case insensitive header name check. r=aswan,robwu, a=RyanVM
toolkit/modules/addons/WebRequest.jsm
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -131,17 +131,17 @@ class HeaderChanger {
         value = String.fromCharCode(...binaryValue);
       }
 
       let lowerCaseName = name.toLowerCase();
       let original = origHeaders.get(lowerCaseName);
 
       if (!original || value !== original.value) {
         let shouldMerge = headersAlreadySet.has(lowerCaseName);
-        this.setHeader(name, value, shouldMerge, opts);
+        this.setHeader(name, value, shouldMerge, opts, lowerCaseName);
       }
 
       headersAlreadySet.add(lowerCaseName);
     }
   }
 }
 
 const checkRestrictedHeaderValue = (value, opts = {}) => {
@@ -153,34 +153,34 @@ const checkRestrictedHeaderValue = (valu
   }
 
   if (WebExtensionPolicy.isRestrictedURI(uri)) {
     throw new Error(`Unable to set host header to restricted url.`);
   }
 };
 
 class RequestHeaderChanger extends HeaderChanger {
-  setHeader(name, value, merge, opts = {}) {
+  setHeader(name, value, merge, opts, lowerCaseName) {
     try {
-      if (name === "host") {
+      if (value && lowerCaseName === "host") {
         checkRestrictedHeaderValue(value, opts);
       }
       this.channel.setRequestHeader(name, value, merge);
     } catch (e) {
       Cu.reportError(new Error(`Error setting request header ${name}: ${e}`));
     }
   }
 
   readHeaders() {
     return this.channel.getRequestHeaders();
   }
 }
 
 class ResponseHeaderChanger extends HeaderChanger {
-  setHeader(name, value, merge, opts = {}) {
+  setHeader(name, value, merge, opts, lowerCaseName) {
     try {
       this.channel.setResponseHeader(name, value, merge);
     } catch (e) {
       Cu.reportError(new Error(`Error setting response header ${name}: ${e}`));
     }
   }
 
   readHeaders() {