Bug 1130318 - Send also header source from the backend. r=vporof
authorJan Odvarko <odvarko@gmail.com>
Wed, 11 Feb 2015 13:49:32 +0100
changeset 242537 a76b4f207fa7d4ca921297c1062900a478647ecd
parent 242536 e0f02f382772e3bcd23a0f83446cf2ba894d1928
child 242538 2ec6877bd567d73627c06718f16027e4f98797f8
push id660
push usermichael.l.comella@gmail.com
push dateThu, 12 Feb 2015 18:55:31 +0000
reviewersvporof
bugs1130318
milestone38.0a1
Bug 1130318 - Send also header source from the backend. r=vporof
toolkit/devtools/server/actors/webconsole.js
toolkit/devtools/webconsole/network-monitor.js
toolkit/devtools/webconsole/test/common.js
toolkit/devtools/webconsole/test/test_network_get.html
toolkit/devtools/webconsole/test/test_network_post.html
--- a/toolkit/devtools/server/actors/webconsole.js
+++ b/toolkit/devtools/server/actors/webconsole.js
@@ -1724,16 +1724,17 @@ NetworkEventActor.prototype =
    *         The response packet - network request headers.
    */
   onGetRequestHeaders: function NEA_onGetRequestHeaders()
   {
     return {
       from: this.actorID,
       headers: this._request.headers,
       headersSize: this._request.headersSize,
+      rawHeaders: this._request.rawHeaders,
     };
   },
 
   /**
    * The "getRequestCookies" packet type handler.
    *
    * @return object
    *         The response packet - network request cookies.
@@ -1782,16 +1783,17 @@ NetworkEventActor.prototype =
    *         The response packet - network response headers.
    */
   onGetResponseHeaders: function NEA_onGetResponseHeaders()
   {
     return {
       from: this.actorID,
       headers: this._response.headers,
       headersSize: this._response.headersSize,
+      rawHeaders: this._response.rawHeaders,
     };
   },
 
   /**
    * The "getResponseCookies" packet type handler.
    *
    * @return object
    *         The response packet - network response cookies.
@@ -1838,22 +1840,30 @@ NetworkEventActor.prototype =
    * Listeners for new network event data coming from NetworkMonitor.
    ******************************************************************/
 
   /**
    * Add network request headers.
    *
    * @param array aHeaders
    *        The request headers array.
+   * @param string aRawHeaders
+   *        The raw headers source.
    */
-  addRequestHeaders: function NEA_addRequestHeaders(aHeaders)
+  addRequestHeaders: function NEA_addRequestHeaders(aHeaders, aRawHeaders)
   {
     this._request.headers = aHeaders;
     this._prepareHeaders(aHeaders);
 
+    var rawHeaders = this.parent._createStringGrip(aRawHeaders);
+    if (typeof rawHeaders == "object") {
+      this._longStringActors.add(rawHeaders);
+    }
+    this._request.rawHeaders = rawHeaders;
+
     let packet = {
       from: this.actorID,
       type: "networkEventUpdate",
       updateType: "requestHeaders",
       headers: aHeaders.length,
       headersSize: this._request.headersSize,
     };
 
@@ -1906,19 +1916,27 @@ NetworkEventActor.prototype =
     this.conn.send(packet);
   },
 
   /**
    * Add the initial network response information.
    *
    * @param object aInfo
    *        The response information.
+   * @param string aRawHeaders
+   *        The raw headers source.
    */
-  addResponseStart: function NEA_addResponseStart(aInfo)
+  addResponseStart: function NEA_addResponseStart(aInfo, aRawHeaders)
   {
+    var rawHeaders = this.parent._createStringGrip(aRawHeaders);
+    if (typeof rawHeaders == "object") {
+      this._longStringActors.add(rawHeaders);
+    }
+    this._response.rawHeaders = rawHeaders;
+
     this._response.httpVersion = aInfo.httpVersion;
     this._response.status = aInfo.status;
     this._response.statusText = aInfo.statusText;
     this._response.headersSize = aInfo.headersSize;
     this._discardResponseBody = aInfo.discardResponseBody;
 
     let packet = {
       from: this.actorID,
--- a/toolkit/devtools/webconsole/network-monitor.js
+++ b/toolkit/devtools/webconsole/network-monitor.js
@@ -791,17 +791,17 @@ NetworkMonitor.prototype = {
     }
 
     httpActivity.owner = this.owner.onNetworkEvent(event, aChannel, this);
 
     this._setupResponseListener(httpActivity);
 
     this.openRequests[httpActivity.id] = httpActivity;
 
-    httpActivity.owner.addRequestHeaders(headers);
+    httpActivity.owner.addRequestHeaders(headers, aExtraStringData);
     httpActivity.owner.addRequestCookies(cookies);
   },
 
   /**
    * Create the empty HTTP activity object. This object is used for storing all
    * the request and response information.
    *
    * This is a HAR-like object. Conformance to the spec is not guaranteed at
@@ -919,17 +919,17 @@ NetworkMonitor.prototype = {
    */
   _onResponseHeader:
   function NM__onResponseHeader(aHttpActivity, aExtraStringData)
   {
     // aExtraStringData contains the uncached response headers. The first line
     // contains the response status (e.g. HTTP/1.1 200 OK).
     //
     // Note: The response header is not saved here. Calling the
-    // channel.visitResponseHeaders() methood at this point sometimes causes an
+    // channel.visitResponseHeaders() method at this point sometimes causes an
     // NS_ERROR_NOT_AVAILABLE exception.
     //
     // We could parse aExtraStringData to get the headers and their values, but
     // that is not trivial to do in an accurate manner. Hence, we save the
     // response headers in this._httpResponseExaminer().
 
     let headers = aExtraStringData.split(/\r\n|\n|\r/);
     let statusLine = headers.shift();
@@ -950,17 +950,17 @@ NetworkMonitor.prototype = {
       case HTTP_SEE_OTHER:
       case HTTP_TEMPORARY_REDIRECT:
         aHttpActivity.discardResponseBody = true;
         break;
     }
 
     response.discardResponseBody = aHttpActivity.discardResponseBody;
 
-    aHttpActivity.owner.addResponseStart(response);
+    aHttpActivity.owner.addResponseStart(response, aExtraStringData);
   },
 
   /**
    * Handler for ACTIVITY_SUBTYPE_TRANSACTION_CLOSE. This method updates the HAR
    * timing information on the HTTP activity object and clears the request
    * from the list of known open requests.
    *
    * @private
--- a/toolkit/devtools/webconsole/test/common.js
+++ b/toolkit/devtools/webconsole/test/common.js
@@ -155,16 +155,34 @@ function checkHeadersOrCookies(aArray, a
 
   for (let header in aExpected) {
     if (!(header in foundHeaders)) {
       ok(false, header + " was not found");
     }
   }
 }
 
+function checkRawHeaders(aText, aExpected)
+{
+  let headers = aText.split(/\r\n|\n|\r/);
+  let arr = [];
+  for (let header of headers) {
+    let index = header.indexOf(": ");
+    if (index < 0) {
+      continue;
+    }
+    arr.push({
+      name: header.substr(0, index),
+      value: header.substr(index + 2)
+    });
+  }
+
+  checkHeadersOrCookies(arr, aExpected);
+}
+
 var gTestState = {};
 
 function runTests(aTests, aEndCallback)
 {
   function driver()
   {
     let lastResult, sendToNext;
     for (let i = 0; i < aTests.length; i++) {
--- a/toolkit/devtools/webconsole/test/test_network_get.html
+++ b/toolkit/devtools/webconsole/test/test_network_get.html
@@ -136,22 +136,28 @@ function onNetworkEventUpdate(aState, aT
 }
 
 function onRequestHeaders(aState, aResponse)
 {
   info("checking request headers");
 
   ok(aResponse.headers.length > 0, "request headers > 0");
   ok(aResponse.headersSize > 0, "request headersSize > 0");
+  ok(!!aResponse.rawHeaders, "request rawHeaders available");
 
   checkHeadersOrCookies(aResponse.headers, {
     Referer: /network_requests_iframe\.html/,
     Cookie: /bug768096/,
   });
 
+  checkRawHeaders(aResponse.rawHeaders, {
+    Referer: /network_requests_iframe\.html/,
+    Cookie: /bug768096/,
+  });
+
   onRequestCookies = onRequestCookies.bind(null, aState);
   aState.client.getRequestCookies(aState.netActor,
                                   onRequestCookies);
 }
 
 function onRequestCookies(aState, aResponse)
 {
   info("checking request cookies");
@@ -182,22 +188,28 @@ function onRequestPostData(aState, aResp
 }
 
 function onResponseHeaders(aState, aResponse)
 {
   info("checking response headers");
 
   ok(aResponse.headers.length > 0, "response headers > 0");
   ok(aResponse.headersSize > 0, "response headersSize > 0");
+  ok(!!aResponse.rawHeaders, "response rawHeaders available");
 
   checkHeadersOrCookies(aResponse.headers, {
     "Content-Type": /^application\/(json|octet-stream)$/,
     "Content-Length": /^\d+$/,
   });
 
+  checkRawHeaders(aResponse.rawHeaders, {
+    "Content-Type": /^application\/(json|octet-stream)$/,
+    "Content-Length": /^\d+$/,
+  });
+
   onResponseCookies = onResponseCookies.bind(null, aState);
   aState.client.getResponseCookies(aState.netActor,
                                   onResponseCookies);
 }
 
 function onResponseCookies(aState, aResponse)
 {
   info("checking response cookies");
--- a/toolkit/devtools/webconsole/test/test_network_post.html
+++ b/toolkit/devtools/webconsole/test/test_network_post.html
@@ -152,22 +152,28 @@ function onNetworkEventUpdate(aState, aT
 }
 
 function onRequestHeaders(aState, aResponse)
 {
   info("checking request headers");
 
   ok(aResponse.headers.length > 0, "request headers > 0");
   ok(aResponse.headersSize > 0, "request headersSize > 0");
+  ok(!!aResponse.rawHeaders.length, "request rawHeaders available");
 
   checkHeadersOrCookies(aResponse.headers, {
     Referer: /network_requests_iframe\.html/,
     Cookie: /bug768096/,
   });
 
+  checkRawHeaders(aResponse.rawHeaders, {
+    Referer: /network_requests_iframe\.html/,
+    Cookie: /bug768096/,
+  });
+
   onRequestCookies = onRequestCookies.bind(null, aState);
   aState.client.getRequestCookies(aState.netActor,
                                   onRequestCookies);
 }
 
 function onRequestCookies(aState, aResponse)
 {
   info("checking request cookies");
@@ -204,22 +210,28 @@ function onRequestPostData(aState, aResp
 }
 
 function onResponseHeaders(aState, aResponse)
 {
   info("checking response headers");
 
   ok(aResponse.headers.length > 0, "response headers > 0");
   ok(aResponse.headersSize > 0, "response headersSize > 0");
+  ok(!!aResponse.rawHeaders, "response rawHeaders available");
 
   checkHeadersOrCookies(aResponse.headers, {
     "Content-Type": /^application\/(json|octet-stream)$/,
     "Content-Length": /^\d+$/,
   });
 
+  checkRawHeaders(aResponse.rawHeaders, {
+    "Content-Type": /^application\/(json|octet-stream)$/,
+    "Content-Length": /^\d+$/,
+  });
+
   onResponseCookies = onResponseCookies.bind(null, aState);
   aState.client.getResponseCookies(aState.netActor,
                                   onResponseCookies);
 }
 
 function onResponseCookies(aState, aResponse)
 {
   info("checking response cookies");