From 370056832227f7329fedb48f78990873a6fa9967 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 19 May 2009 14:46:07 +0200 Subject: [PATCH] Add request method. (How could that be missing still?) --- src/http.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/http.cc b/src/http.cc index 203c05f0f0e..be0f478130a 100644 --- a/src/http.cc +++ b/src/http.cc @@ -21,6 +21,7 @@ #define ON_BODY_SYMBOL String::NewSymbol("onBody") #define ON_MESSAGE_COMPLETE_SYMBOL String::NewSymbol("onMessageComplete") +#define METHOD_SYMBOL String::NewSymbol("method") #define STATUS_CODE_SYMBOL String::NewSymbol("status_code") #define HTTP_VERSION_SYMBOL String::NewSymbol("http_version") #define SHOULD_KEEP_ALIVE_SYMBOL String::NewSymbol("should_keep_alive") @@ -135,6 +136,28 @@ DEFINE_PARSER_CALLBACK(on_uri, ON_URI_SYMBOL) DEFINE_PARSER_CALLBACK(on_header_field, ON_HEADER_FIELD_SYMBOL) DEFINE_PARSER_CALLBACK(on_header_value, ON_HEADER_VALUE_SYMBOL) +static Local +GetMethod (int method) +{ + switch (method) { + case HTTP_COPY: return String::NewSymbol("COPY"); + case HTTP_DELETE: return String::NewSymbol("DELETE"); + case HTTP_GET: return String::NewSymbol("GET"); + case HTTP_HEAD: return String::NewSymbol("HEAD"); + case HTTP_LOCK: return String::NewSymbol("LOCK"); + case HTTP_MKCOL: return String::NewSymbol("MKCOL"); + case HTTP_MOVE: return String::NewSymbol("MOVE"); + case HTTP_OPTIONS: return String::NewSymbol("OPTIONS"); + case HTTP_POST: return String::NewSymbol("POST"); + case HTTP_PROPFIND: return String::NewSymbol("PROPFIND"); + case HTTP_PROPPATCH: return String::NewSymbol("PROPPATCH"); + case HTTP_PUT: return String::NewSymbol("PUT"); + case HTTP_TRACE: return String::NewSymbol("TRACE"); + case HTTP_UNLOCK: return String::NewSymbol("UNLOCK"); + } + return Local(); +} + int HTTPConnection::on_headers_complete (http_parser *parser) { @@ -145,6 +168,9 @@ HTTPConnection::on_headers_complete (http_parser *parser) connection->handle_->GetHiddenValue(MESSAGE_HANDLER_SYMBOL); Local message_handler = message_handler_v->ToObject(); + // METHOD + message_handler->Set(METHOD_SYMBOL, GetMethod(connection->parser_.method)); + // STATUS message_handler->Set(STATUS_CODE_SYMBOL, Integer::New(connection->parser_.status_code));