node_pcap icon indicating copy to clipboard operation
node_pcap copied to clipboard

Response initialisation doesn't work with pipelining

Open mnot opened this issue 14 years ago • 0 comments

http.response is initialised in the request's onMessageStart, which means that if two responses are received without an intervening HTTP request (e.g., when pipelining happens), the new one will overwrite the old one.

The patch below moves the init to the response's onMessageStart. That doesn't completely fix things, as someone accessing http.request from the response's context will get the wrong request. However, that's really a separate bug.

diff --git a/pcap.js b/pcap.js
index 5083d69..d69116c 100644
--- a/pcap.js
+++ b/pcap.js
@@ -1125,6 +1125,12 @@ TCP_tracker.prototype.setup_http_tracking = function (session) {
             body_len: 0,
             http_version: null
         };
+        http.response = {
+            headers: {},
+            status_code: null,
+            body_len: 0,
+            http_version: null
+        };

         http.request_parser.onURL = function (buf, start, len) {
             var url_string = buf.toString('ascii', start, start + len);
@@ -1181,13 +1187,6 @@ TCP_tracker.prototype.setup_http_tracking = function (session) {

     http.response_parser = new HTTPParser('response');
     http.response_parser.onMessageBegin = function () {
-        http.response = {
-            headers: {},
-            status_code: null,
-            body_len: 0,
-            http_version: null
-        };
-
         http.response_parser.onHeaderField = function (buf, start, len) {
             var field = buf.toString('ascii', start, start + len);
             if (http.response_parser.header_value) {

mnot avatar Feb 25 '11 04:02 mnot