Bug 1278923 - Export Content-Type and Content-Length to HAR headers. r=Honza
authorRicky Chien <ricky060709@gmail.com>
Mon, 01 Aug 2016 19:27:05 +0800
changeset 400791 c73cad6f6773ad295e2029da453406947be089f8
parent 400790 39cd9b527d38af339390f5a7d9c522facf5f3b99
child 400792 dbb9da97e0e1c021314baf7de44f82fd4a74058d
push id26284
push usermwein@mozilla.com
push dateMon, 15 Aug 2016 20:48:20 +0000
reviewersHonza
bugs1278923
milestone51.0a1
Bug 1278923 - Export Content-Type and Content-Length to HAR headers. r=Honza MozReview-Commit-ID: H0eZ8bSId8Q
devtools/client/netmonitor/har/har-builder.js
--- a/devtools/client/netmonitor/har/har-builder.js
+++ b/devtools/client/netmonitor/har/har-builder.js
@@ -160,16 +160,17 @@ HarBuilder.prototype = {
       bodySize: 0
     };
 
     request.method = file.method;
     request.url = file.url;
     request.httpVersion = file.httpVersion || "";
 
     request.headers = this.buildHeaders(file.requestHeaders);
+    request.headers = this.appendHeadersPostData(request.headers, file);
     request.cookies = this.buildCookies(file.requestCookies);
 
     request.queryString = NetworkHelper.parseQueryString(
       NetworkHelper.nsIURL(file.url).query) || [];
 
     request.postData = this.buildPostData(file);
 
     request.headersSize = file.requestHeaders.headersSize;
@@ -194,16 +195,43 @@ HarBuilder.prototype = {
   buildHeaders: function (input) {
     if (!input) {
       return [];
     }
 
     return this.buildNameValuePairs(input.headers);
   },
 
+  appendHeadersPostData: function (input = [], file) {
+    if (!file.requestPostData) {
+      return input;
+    }
+
+    this.fetchData(file.requestPostData.postData.text).then(value => {
+      let contentType = value.match(/Content-Type: ([^;\s]+)/);
+      let contentLength = value.match(/Content-Length: (.+)/);
+
+      if (contentType && contentType.length > 1) {
+        input.push({
+          name: "Content-Type",
+          value: contentType[1]
+        });
+      }
+
+      if (contentLength && contentLength.length > 1) {
+        input.push({
+          name: "Content-Length",
+          value: contentLength[1]
+        });
+      }
+    });
+
+    return input;
+  },
+
   buildCookies: function (input) {
     if (!input) {
       return [];
     }
 
     return this.buildNameValuePairs(input.cookies);
   },