Permalink
Browse files

WIP

  • Loading branch information...
bnoordhuis committed Oct 26, 2012
1 parent f38749a commit e96febe4b8358805083fa31bdf21003d50039436
Showing with 108 additions and 185 deletions.
  1. +27 −22 lib/http.js
  2. +81 −163 src/node_http_parser.cc
View
@@ -19,6 +19,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
+var assert = require('assert');
var util = require('util');
var net = require('net');
var Stream = require('stream');
@@ -37,46 +38,50 @@ if (process.env.NODE_DEBUG && /http/.test(process.env.NODE_DEBUG)) {
debug = function() { };
}
+
+function stringify(buf, start, end) {
+ // XXX optimize somehow?
+ return buf.toString('utf8', start, end);
+}
+
+
// 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
// processed in a single run. This method is also
// called to process trailing HTTP headers.
-function parserOnHeaders(headers, url) {
+function parserOnHeaders(buf, offsets, noffsets, hasURL) {
+ assert(noffsets % 2 == 0, 'noffsets % 2 == 0');
+
+ if (hasURL) {
+ this._url = stringify(buf, offsets[0], offsets[1]);
+ }
+
// Once we exceeded headers limit - stop collecting them
- if (this.maxHeaderPairs <= 0 ||
- this._headers.length < this.maxHeaderPairs) {
- this._headers = this._headers.concat(headers);
+ if (this.maxHeaderPairs > 0 && this._headers.length >= this.maxHeaderPairs) {
+ return;
+ }
+
+ for (var i = hasURL ? 2 : 0; i < noffsets; i += 2) {
+ this._headers.push(stringify(buf, offsets[i], offsets[i + 1]));
}
- this._url += url;
}
-// info.headers and info.url are set only if .onHeaders()
-// has not been called for this request.
-//
-// info.url is not set for response parsers but that's not
-// applicable here since all our parsers are request parsers.
-function parserOnHeadersComplete(info) {
- var parser = this;
- var headers = info.headers;
- var url = info.url;
- if (!headers) {
- headers = parser._headers;
- parser._headers = [];
- }
+function parserOnHeadersComplete(info, buf, offsets, noffsets, first) {
+ var parser = this;
- if (!url) {
- url = parser._url;
- parser._url = '';
+ if (noffsets >= 2) { // noffsets <= 1 means no path, no headers
+ parserOnHeaders.call(parser, buf, offsets, noffsets, first);
}
parser.incoming = new IncomingMessage(parser.socket);
parser.incoming.httpVersionMajor = info.versionMajor;
parser.incoming.httpVersionMinor = info.versionMinor;
parser.incoming.httpVersion = info.versionMajor + '.' + info.versionMinor;
- parser.incoming.url = url;
+ parser.incoming.url = parser._url;
+ var headers = parser._headers;
var n = headers.length;
// If parser.maxHeaderPairs <= 0 - assume that there're no limit
Oops, something went wrong.

0 comments on commit e96febe

Please sign in to comment.