Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/lib/http.js b/lib/http.js
index 912e3da..343d48b 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -39,9 +39,23 @@ if (process.env.NODE_DEBUG && /http/.test(process.env.NODE_DEBUG)) {
var parsers = new FreeList('parsers', 1000, function() {
var parser = new HTTPParser(HTTPParser.REQUEST);
+ // Retain a reference to the parser input until the headers have been parsed.
+ parser._headersComplete = false;
+ parser._buffers = [];
parser._headers = [];
parser._url = '';
+ parser.execute = function(data, start, end) {
+ if (!parser._headersComplete) parser._buffers.push(data);
+ return HTTPParser.prototype.execute.call(parser, data, start, end);
+ };
+
+ parser.reinitialize = function(type) {
+ parser._headersComplete = false;
+ parser._buffers = [];
+ return HTTPParser.prototype.reinitialize.call(parser, type);
+ };
+
// Only called in the slow case where slow means
// that the request headers were either fragmented
// across multiple TCP packets or too large to be
@@ -61,6 +75,9 @@ var parsers = new FreeList('parsers', 1000, function() {
var headers = info.headers;
var url = info.url;
+ parser._headersComplete = true;
+ parser._buffers = [];
+
if (!headers) {
headers = parser._headers;
parser._headers = [];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.