Bug 1305162: Part 2 - Remove support for upload streams with embedded headers. r=mixedpuppy,dragana
☠☠ backed out by 81824fdf77fb ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Fri, 09 Dec 2016 14:02:05 -1000
changeset 375523 1a23ce5a17c338a9ef902d4f30e586ad4444af36
parent 375522 d1095e03dfc600771f54c7ff2dc5fd294ca1ab28
child 375524 c633650caea682de11142d5cb6d28f3effcadf55
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, dragana
bugs1305162
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1305162: Part 2 - Remove support for upload streams with embedded headers. r=mixedpuppy,dragana MozReview-Commit-ID: CuqOmas4WDM
toolkit/modules/addons/WebRequestUpload.jsm
--- a/toolkit/modules/addons/WebRequestUpload.jsm
+++ b/toolkit/modules/addons/WebRequestUpload.jsm
@@ -363,43 +363,21 @@ function parseFormData(stream, channel, 
       let [name, value] = part.replace(/\+/g, " ").split("=").map(decodeURIComponent);
       formData.get(name).push(value);
     }
 
     return formData;
   }
 
   try {
-    let headers;
     if (stream instanceof Ci.nsIMIMEInputStream && stream.data) {
-      if (channel instanceof Ci.nsIUploadChannel2 && channel.uploadStreamHasHeaders) {
-        // MIME input streams encode additional headers as a block at the
-        // beginning of their stream. The actual request data comes from a
-        // sub-stream, which is accessible via their `data` member. The
-        // difference in available bytes between the outer stream and the
-        // inner data stream tells us the size of that header block.
-        //
-        // Since we need to know at least the value of the Content-Type
-        // header to properly parse the request body, we need to read and
-        // parse the header block in order to extract it.
-
-        headers = readString(createTextStream(stream),
-                             stream.available() - stream.data.available());
-      }
-
-      rewind(stream);
       stream = stream.data;
     }
 
-    let contentType;
-    try {
-      contentType = channel.getRequestHeader("Content-Type");
-    } catch (e) {
-      contentType = new Headers(headers).get("content-type");
-    }
+    let contentType = channel.getRequestHeader("Content-Type");
 
     switch (Headers.getParam(contentType, "")) {
       case "multipart/form-data":
         let boundary = Headers.getParam(contentType, "boundary");
         return parseMultiPart(stream, `\r\n--${boundary}`);
 
       case "application/x-www-form-urlencoded":
         return parseUrlEncoded(stream);
@@ -499,36 +477,40 @@ function* getRawDataChunked(outerStream,
     } finally {
       rewind(stream);
     }
   }
 }
 
 WebRequestUpload = {
   createRequestBody(channel) {
-    if (channel instanceof Ci.nsIUploadChannel && channel.uploadStream) {
-      try {
-        let stream = channel.uploadStream;
-
-        let formData = createFormData(stream, channel);
-        if (formData) {
-          return {formData};
-        }
+    if (!(channel instanceof Ci.nsIUploadChannel) || !channel.uploadStream) {
+      return null;
+    }
 
-        // If we failed to parse the stream as form data, return it as a
-        // sequence of raw data chunks, along with a leniently-parsed form
-        // data object, which ignores encoding errors.
-        return {
-          raw: Array.from(getRawDataChunked(stream)),
-          lenientFormData: createFormData(stream, channel, true),
-        };
-      } catch (e) {
-        Cu.reportError(e);
-        return {error: e.message || String(e)};
-      }
+    if (channel instanceof Ci.nsIUploadChannel2 && channel.uploadStreamHasHeaders) {
+      return {error: "Upload streams with headers are unsupported"};
     }
 
-    return null;
+    try {
+      let stream = channel.uploadStream;
+
+      let formData = createFormData(stream, channel);
+      if (formData) {
+        return {formData};
+      }
+
+      // If we failed to parse the stream as form data, return it as a
+      // sequence of raw data chunks, along with a leniently-parsed form
+      // data object, which ignores encoding errors.
+      return {
+        raw: Array.from(getRawDataChunked(stream)),
+        lenientFormData: createFormData(stream, channel, true),
+      };
+    } catch (e) {
+      Cu.reportError(e);
+      return {error: e.message || String(e)};
+    }
   },
 };
 
 XPCOMUtils.defineLazyPreferenceGetter(WebRequestUpload, "MAX_RAW_BYTES",
                                       "webextensions.webRequest.requestBodyMaxRawBytes");