From 175223d5d798e86b8c4d162e742a3a22d22ca3e4 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 16 May 2009 12:49:33 +0200 Subject: [PATCH] Remove HTTP parser callbacks for fragment, query_string, path. Instead we're going to just get a single callback for the URI. This can be parsed additionally in javascript using parseuri: http://blog.stevenlevithan.com/archives/parseuri I haven't added that yet, but it will come soon. --- src/http.cc | 6 ------ src/http.h | 3 --- src/http.js | 6 ------ test-http_simple.js | 20 +++++++++++++++----- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/http.cc b/src/http.cc index 994ddfc7285..0140c530ceb 100644 --- a/src/http.cc +++ b/src/http.cc @@ -131,10 +131,7 @@ HTTPConnection::name (http_parser *parser, const char *buf, size_t len) \ return 0; \ } -DEFINE_PARSER_CALLBACK(on_path, ON_PATH_SYMBOL) -DEFINE_PARSER_CALLBACK(on_query_string, ON_QUERY_STRING_SYMBOL) DEFINE_PARSER_CALLBACK(on_uri, ON_URI_SYMBOL) -DEFINE_PARSER_CALLBACK(on_fragment, ON_FRAGMENT_SYMBOL) DEFINE_PARSER_CALLBACK(on_header_field, ON_HEADER_FIELD_SYMBOL) DEFINE_PARSER_CALLBACK(on_header_value, ON_HEADER_VALUE_SYMBOL) @@ -275,10 +272,7 @@ HTTPConnection::HTTPConnection (Handle handle, enum http_parser_type typ { http_parser_init (&parser_, type); parser_.on_message_begin = on_message_begin; - parser_.on_path = on_path; - parser_.on_query_string = on_query_string; parser_.on_uri = on_uri; - parser_.on_fragment = on_fragment; parser_.on_header_field = on_header_field; parser_.on_header_value = on_header_value; parser_.on_headers_complete = on_headers_complete; diff --git a/src/http.h b/src/http.h index a3c140c78f4..62ee3c353f4 100644 --- a/src/http.h +++ b/src/http.h @@ -25,10 +25,7 @@ protected: void OnReceive (const void *buf, size_t len); static int on_message_begin (http_parser *parser); - static int on_path (http_parser *parser, const char *at, size_t length); - static int on_query_string (http_parser *parser, const char *at, size_t length); static int on_uri (http_parser *parser, const char *at, size_t length); - static int on_fragment (http_parser *parser, const char *at, size_t length); static int on_header_field (http_parser *parser, const char *buf, size_t len); static int on_header_value (http_parser *parser, const char *buf, size_t len); static int on_headers_complete (http_parser *parser); diff --git a/src/http.js b/src/http.js index fc960260379..f9c16067ca0 100644 --- a/src/http.js +++ b/src/http.js @@ -211,16 +211,10 @@ node.http.Server = function (RequestHandler, options) { connection.onMessage = function ( ) { var msg = new Message(); - msg.path = ""; msg.uri = ""; - msg.query_string = ""; - msg.fragment = ""; var headers = msg.headers = []; - this.onPath = function (data) { msg.path += data; return true }; this.onURI = function (data) { msg.uri += data; return true }; - this.onQueryString = function (data) { msg.query_string += data; return true; }; - this.onFragment = function (data) { msg.fragment += data; return true; }; var last_was_value = false; diff --git a/test-http_simple.js b/test-http_simple.js index 0a3f44b3a6c..58f6b8a8c53 100644 --- a/test-http_simple.js +++ b/test-http_simple.js @@ -1,7 +1,12 @@ +fixed = "" +for (var i = 0; i < 20*1024; i++) { + fixed += "C"; +} +stored = {}; new node.http.Server(function (msg) { - var commands = msg.path.split("/"); - var body = ""; + var commands = msg.uri.split("/"); var command = commands[1]; + var body = ""; var arg = commands[2]; var status = 200; @@ -11,16 +16,21 @@ new node.http.Server(function (msg) { var n = parseInt(arg, 10) if (n <= 0) throw "bytes called with n <= 0" - for (var i = 0; i < n; i++) { - body += "C" + if (stored[n] === undefined) { + puts("create stored[n]"); + stored[n] = ""; + for (var i = 0; i < n; i++) { + stored[n] += "C" + } } + body = stored[n]; } else if (command == "quit") { msg.connection.server.close(); body = "quitting"; } else if (command == "fixed") { - body = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"; + body = fixed; } else { status = 404;