Add http_status_str() function.

Fixes: https://github.com/nodejs/http-parser/issues/371
PR-URL: https://github.com/nodejs/http-parser/pull/429
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
make-http-max-header-size-gyp-configurable
Stefano Sambi 7 years ago committed by Ben Noordhuis
parent a7c2e8626b
commit 2ed7527795

@ -2096,6 +2096,16 @@ http_method_str (enum http_method m)
return ELEM_AT(method_strings, m, "<unknown>"); return ELEM_AT(method_strings, m, "<unknown>");
} }
const char *
http_status_str (enum http_status s)
{
switch (s) {
#define XX(num, name, string) case HTTP_STATUS_##name: return #string;
HTTP_STATUS_MAP(XX)
#undef XX
default: return "<unknown>";
}
}
void void
http_parser_init (http_parser *parser, enum http_parser_type t) http_parser_init (http_parser *parser, enum http_parser_type t)

@ -407,6 +407,9 @@ int http_should_keep_alive(const http_parser *parser);
/* Returns a string version of the HTTP method. */ /* Returns a string version of the HTTP method. */
const char *http_method_str(enum http_method m); const char *http_method_str(enum http_method m);
/* Returns a string version of the HTTP status code. */
const char *http_status_str(enum http_status s);
/* Return a string name of the given error */ /* Return a string name of the given error */
const char *http_errno_name(enum http_errno err); const char *http_errno_name(enum http_errno err);

@ -3374,6 +3374,14 @@ test_method_str (void)
assert(0 == strcmp("<unknown>", http_method_str(1337))); assert(0 == strcmp("<unknown>", http_method_str(1337)));
} }
void
test_status_str (void)
{
assert(0 == strcmp("OK", http_status_str(HTTP_STATUS_OK)));
assert(0 == strcmp("Not Found", http_status_str(HTTP_STATUS_NOT_FOUND)));
assert(0 == strcmp("<unknown>", http_status_str(1337)));
}
void void
test_message (const struct message *message) test_message (const struct message *message)
{ {
@ -4104,6 +4112,7 @@ main (void)
test_preserve_data(); test_preserve_data();
test_parse_url(); test_parse_url();
test_method_str(); test_method_str();
test_status_str();
//// NREAD //// NREAD
test_header_nread_value(); test_header_nread_value();

Loading…
Cancel
Save