From ee8530e0ee386492ca519004cfaa34de650b17b3 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 7 Dec 2009 15:21:12 +0100 Subject: [PATCH] offload method look up to http-parser --- deps/http_parser/http_parser.h | 53 ++++++++++++++++++++++++---------- deps/http_parser/test.c | 5 ++-- src/node_http.cc | 29 ++----------------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/deps/http_parser/http_parser.h b/deps/http_parser/http_parser.h index bd3123a9186..9d14bbf5bf8 100644 --- a/deps/http_parser/http_parser.h +++ b/deps/http_parser/http_parser.h @@ -55,22 +55,23 @@ typedef int (*http_cb) (http_parser*); /* Request Methods */ enum http_method - { HTTP_DELETE = 0x0002 - , HTTP_GET = 0x0004 - , HTTP_HEAD = 0x0008 - , HTTP_POST = 0x0010 - , HTTP_PUT = 0x0020 - /* webdav methods */ - , HTTP_COPY = 0x0040 - , HTTP_LOCK = 0x0080 - , HTTP_MKCOL = 0x0100 - , HTTP_MOVE = 0x0200 - , HTTP_OPTIONS = 0x0400 - , HTTP_PROPFIND = 0x0800 - , HTTP_PROPPATCH = 0x1000 - , HTTP_TRACE = 0x2000 + { HTTP_DELETE = 0x0001 + , HTTP_GET = 0x0002 + , HTTP_HEAD = 0x0004 + , HTTP_POST = 0x0008 + , HTTP_PUT = 0x0010 + /* pathological */ + , HTTP_CONNECT = 0x0020 + , HTTP_OPTIONS = 0x0040 + , HTTP_TRACE = 0x0080 + /* webdav */ + , HTTP_COPY = 0x0100 + , HTTP_LOCK = 0x0200 + , HTTP_MKCOL = 0x0400 + , HTTP_MOVE = 0x0800 + , HTTP_PROPFIND = 0x1000 + , HTTP_PROPPATCH = 0x2000 , HTTP_UNLOCK = 0x4000 - , HTTP_CONNECT = 0x8000 }; struct http_parser { @@ -134,6 +135,28 @@ size_t http_parse_responses(http_parser *parser, const char *data, size_t len); */ int http_should_keep_alive(http_parser *parser); +static inline const char * http_method_str (enum http_method method) +{ + switch (method) { + case HTTP_DELETE: return "DELETE"; + case HTTP_GET: return "GET"; + case HTTP_HEAD: return "HEAD"; + case HTTP_POST: return "POST"; + case HTTP_PUT: return "PUT"; + case HTTP_CONNECT: return "CONNECT"; + case HTTP_OPTIONS: return "OPTIONS"; + case HTTP_TRACE: return "TRACE"; + case HTTP_COPY: return "COPY"; + case HTTP_LOCK: return "LOCK"; + case HTTP_MKCOL: return "MKCOL"; + case HTTP_MOVE: return "MOVE"; + case HTTP_PROPFIND: return "PROPFIND"; + case HTTP_PROPPATCH: return "PROPPATCH"; + case HTTP_UNLOCK: return "UNLOCK"; + default: return (const char*)0; + } +} + #ifdef __cplusplus } #endif diff --git a/deps/http_parser/test.c b/deps/http_parser/test.c index b42ffd559be..f8cf268dc5d 100644 --- a/deps/http_parser/test.c +++ b/deps/http_parser/test.c @@ -1049,10 +1049,12 @@ main (void) printf("sizeof(http_parser) = %d\n", sizeof(http_parser)); + assert(strcmp(http_method_str(HTTP_GET), "GET") == 0); + assert(strcmp(http_method_str(HTTP_CONNECT), "CONNECT") == 0); + for (request_count = 0; requests[request_count].name; request_count++); for (response_count = 0; responses[response_count].name; response_count++); -#if 0 //// RESPONSES for (i = 0; i < response_count; i++) { @@ -1076,7 +1078,6 @@ main (void) ); puts("responses okay"); -#endif /// REQUESTS diff --git a/src/node_http.cc b/src/node_http.cc index 5b4c332de66..40708192181 100644 --- a/src/node_http.cc +++ b/src/node_http.cc @@ -200,32 +200,6 @@ HTTPConnection::on_header_value (http_parser *parser, const char *buf, size_t le return 0; } -static inline Local -GetMethod (int method) -{ - const char *s; - switch (method) { - case HTTP_DELETE: s = "DELETE"; break; - case HTTP_GET: s = "GET"; break; - case HTTP_HEAD: s = "HEAD"; break; - case HTTP_POST: s = "POST"; break; - case HTTP_PUT: s = "PUT"; break; - case HTTP_COPY: s = "COPY"; break; - case HTTP_LOCK: s = "LOCK"; break; - case HTTP_MKCOL: s = "MKCOL"; break; - case HTTP_MOVE: s = "MOVE"; break; - case HTTP_OPTIONS: s = "OPTIONS"; break; - case HTTP_PROPFIND: s = "PROPFIND"; break; - case HTTP_PROPPATCH: s = "PROPPATCH"; break; - case HTTP_TRACE: s = "TRACE"; break; - case HTTP_UNLOCK: s = "UNLOCK"; break; - case HTTP_CONNECT: s = "CONNECT"; break; - } - HandleScope scope; - Local method = String::NewSymbol(s); - return scope.Close(method); -} - int HTTPConnection::on_headers_complete (http_parser *parser) { @@ -237,7 +211,8 @@ HTTPConnection::on_headers_complete (http_parser *parser) // METHOD if (connection->type_ == HTTP_REQUEST) { - message_info->Set(METHOD_SYMBOL, GetMethod(connection->parser_.method)); + message_info->Set(METHOD_SYMBOL, String::NewSymbol( + http_method_str(connection->parser_.method))); } // STATUS