From ddbd5c3728e2663166d84917e178b2d915958c32 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 20 Jun 2010 13:21:36 -0700 Subject: [PATCH] Expose http_method_str() to get a string version of a method --- http_parser.c | 53 +++++++++++++++++++++++++++++---------------------- http_parser.h | 2 ++ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/http_parser.c b/http_parser.c index abfdc8c..a2a07f8 100644 --- a/http_parser.c +++ b/http_parser.c @@ -77,6 +77,29 @@ do { \ #define CLOSE "close" +static const char *method_strings[] = + { "DELETE" + , "GET" + , "HEAD" + , "POST" + , "PUT" + , "CONNECT" + , "OPTIONS" + , "TRACE" + , "COPY" + , "LOCK" + , "MKCOL" + , "MOVE" + , "PROPFIND" + , "PROPPATCH" + , "UNLOCK" + , "REPORT" + , "MKACTIVITY" + , "CHECKOUT" + , "MERGE" + }; + + static const char lowcase[256] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0-\0\0" "0123456789\0\0\0\0\0\0" @@ -527,28 +550,7 @@ size_t http_parser_execute (http_parser *parser, if (ch == '\0') goto error; - static const char *match_strs[] = { - "DELETE", - "GET", - "HEAD", - "POST", - "PUT", - "CONNECT", - "OPTIONS", - "TRACE", - "COPY", - "LOCK", - "MKCOL", - "MOVE", - "PROPFIND", - "PROPPATCH", - "UNLOCK", - "REPORT", - "MKACTIVITY", - "CHECKOUT", - "MERGE" }; - - const char *matcher = match_strs[parser->method]; + const char *matcher = method_strings[parser->method]; if (ch == ' ' && matcher[index] == '\0') { state = s_req_spaces_before_url; } else if (ch == matcher[index]) { @@ -1520,6 +1522,12 @@ http_should_keep_alive (http_parser *parser) } +const char * http_method_str (enum http_method m) +{ + return method_strings[m]; +} + + void http_parser_init (http_parser *parser, enum http_parser_type t) { @@ -1528,4 +1536,3 @@ http_parser_init (http_parser *parser, enum http_parser_type t) parser->nread = 0; parser->upgrade = 0; } - diff --git a/http_parser.h b/http_parser.h index 8265111..1895d79 100644 --- a/http_parser.h +++ b/http_parser.h @@ -154,6 +154,8 @@ size_t http_parser_execute(http_parser *parser, */ int http_should_keep_alive(http_parser *parser); +/* Returns a string version of the HTTP method. */ +const char *http_method_str(enum http_method); #ifdef __cplusplus }