Bug 1174095 - Do not add 'postData' to HAR requests if there isn't any posted data r=Honza
authorXavier ALT <dex@phoenix-ind.net>
Sat, 19 Aug 2017 00:05:57 +0200
changeset 376965 72adcbfccfbe508a4c51c47551b6b6e0721d1818
parent 376964 f384a3acd01687f4f8cc55333298aebb02c33532
child 376966 4251e7033a49f9a857261c20476518fefc1b4d43
push id32397
push userphilringnalda@gmail.com
push dateSun, 27 Aug 2017 01:13:26 +0000
treeherdermozilla-central@30ee0dcda883 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1174095
milestone57.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 1174095 - Do not add 'postData' to HAR requests if there isn't any posted data r=Honza MozReview-Commit-ID: GNySOInGDVz
devtools/client/netmonitor/src/har/har-builder.js
devtools/client/netmonitor/src/har/test/browser.ini
devtools/client/netmonitor/src/har/test/browser_net_har_post_data_on_get.js
devtools/client/netmonitor/src/har/test/html_har_post-data-test-page.html
--- a/devtools/client/netmonitor/src/har/har-builder.js
+++ b/devtools/client/netmonitor/src/har/har-builder.js
@@ -160,17 +160,19 @@ HarBuilder.prototype = {
     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 = parseQueryString(getUrlQuery(file.url)) || [];
 
-    request.postData = this.buildPostData(file);
+    if (file.requestPostData) {
+      request.postData = this.buildPostData(file);
+    }
 
     request.headersSize = file.requestHeaders.headersSize;
 
     // Set request body size, but make sure the body is fetched
     // from the backend.
     if (file.requestPostData) {
       this.fetchData(file.requestPostData.postData.text).then(value => {
         request.bodySize = value.length;
--- a/devtools/client/netmonitor/src/har/test/browser.ini
+++ b/devtools/client/netmonitor/src/har/test/browser.ini
@@ -6,8 +6,9 @@ support-files =
   head.js
   html_har_post-data-test-page.html
   !/devtools/client/netmonitor/test/head.js
   !/devtools/client/netmonitor/test/html_simple-test-page.html
 
 [browser_net_har_copy_all_as_har.js]
 [browser_net_har_post_data.js]
 [browser_net_har_throttle_upload.js]
+[browser_net_har_post_data_on_get.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/src/har/test/browser_net_har_post_data_on_get.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests for exporting POST data into HAR format.
+ */
+add_task(function* () {
+  let { tab, monitor } = yield initNetMonitor(
+    HAR_EXAMPLE_URL + "html_har_post-data-test-page.html");
+
+  info("Starting test... ");
+
+  let { store, windowRequire } = monitor.panelWin;
+  let Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+  let RequestListContextMenu = windowRequire(
+    "devtools/client/netmonitor/src/request-list-context-menu");
+
+  store.dispatch(Actions.batchEnable(false));
+
+  // Execute one GET request on the page and wait till its done.
+  let wait = waitForNetworkEvents(monitor, 1);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.wrappedJSObject.executeTest3();
+  });
+  yield wait;
+
+  // Copy HAR into the clipboard (asynchronous).
+  let contextMenu = new RequestListContextMenu({});
+  let jsonString = yield contextMenu.copyAllAsHar();
+  let har = JSON.parse(jsonString);
+
+  // Check out the HAR log.
+  isnot(har.log, null, "The HAR log must exist");
+  is(har.log.pages.length, 1, "There must be one page");
+  is(har.log.entries.length, 1, "There must be one request");
+
+  let entry = har.log.entries[0];
+  is(entry.request.postData, undefined,
+    "Check post data is not present");
+
+  // Clean up
+  return teardown(monitor);
+});
--- a/devtools/client/netmonitor/src/har/test/html_har_post-data-test-page.html
+++ b/devtools/client/netmonitor/src/har/test/html_har_post-data-test-page.html
@@ -11,33 +11,45 @@
     <meta http-equiv="Expires" content="0" />
     <title>Network Monitor Test Page</title>
   </head>
 
   <body>
     <p>HAR POST data test</p>
 
     <script type="text/javascript">
-      /* exported executeTest, executeTest2 */
+      /* exported executeTest, executeTest2, executeTest3 */
       "use strict";
 
       function post(address, data) {
         let xhr = new XMLHttpRequest();
         xhr.open("POST", address, true);
         xhr.setRequestHeader("Content-Type", "application/json");
         xhr.send(data);
       }
 
+      function get(address) {
+        let xhr = new XMLHttpRequest();
+        xhr.open("GET", address);
+        xhr.send();
+      }
+
       function executeTest() {
         const url = "html_har_post-data-test-page.html";
         const data = "{'first': 'John', 'last': 'Doe'}";
         post(url, data);
       }
 
       function executeTest2(size) {
         const url = "html_har_post-data-test-page.html";
         const data = "x".repeat(size);
         post(url, data);
       }
+
+      function executeTest3(size) {
+        const url = "html_har_post-data-test-page.html";
+        get(url);
+      }
+
     </script>
   </body>
 
 </html>