File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2096,6 +2096,16 @@ http_method_str (enum http_method m)
2096
2096
return ELEM_AT (method_strings , m , "<unknown>" );
2097
2097
}
2098
2098
2099
+ const char *
2100
+ http_status_str (enum http_status s )
2101
+ {
2102
+ switch (s ) {
2103
+ #define XX (num , name , string ) case HTTP_STATUS_##name: return #string;
2104
+ HTTP_STATUS_MAP (XX )
2105
+ #undef XX
2106
+ default : return "<unknown>" ;
2107
+ }
2108
+ }
2099
2109
2100
2110
void
2101
2111
http_parser_init (http_parser * parser , enum http_parser_type t )
Original file line number Diff line number Diff line change @@ -407,6 +407,9 @@ int http_should_keep_alive(const http_parser *parser);
407
407
/* Returns a string version of the HTTP method. */
408
408
const char * http_method_str (enum http_method m );
409
409
410
+ /* Returns a string version of the HTTP status code. */
411
+ const char * http_status_str (enum http_status s );
412
+
410
413
/* Return a string name of the given error */
411
414
const char * http_errno_name (enum http_errno err );
412
415
Original file line number Diff line number Diff line change @@ -3374,6 +3374,14 @@ test_method_str (void)
3374
3374
assert (0 == strcmp ("<unknown>" , http_method_str (1337 )));
3375
3375
}
3376
3376
3377
+ void
3378
+ test_status_str (void )
3379
+ {
3380
+ assert (0 == strcmp ("OK" , http_status_str (HTTP_STATUS_OK )));
3381
+ assert (0 == strcmp ("Not Found" , http_status_str (HTTP_STATUS_NOT_FOUND )));
3382
+ assert (0 == strcmp ("<unknown>" , http_status_str (1337 )));
3383
+ }
3384
+
3377
3385
void
3378
3386
test_message (const struct message * message )
3379
3387
{
@@ -4104,6 +4112,7 @@ main (void)
4104
4112
test_preserve_data ();
4105
4113
test_parse_url ();
4106
4114
test_method_str ();
4115
+ test_status_str ();
4107
4116
4108
4117
//// NREAD
4109
4118
test_header_nread_value ();
You can’t perform that action at this time.
0 commit comments