/* 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 {
*/
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
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++) {
);
puts("responses okay");
-#endif
/// REQUESTS
return 0;
}
-static inline Local<String>
-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<String> method = String::NewSymbol(s);
- return scope.Close(method);
-}
-
int
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