Skip to content

Commit

Permalink
add on_reason to get the reason string from a response parse
Browse files Browse the repository at this point in the history
  • Loading branch information
toffaletti committed Aug 16, 2011
1 parent 918a071 commit 3b75bc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 11 additions & 10 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ size_t http_parser_execute (http_parser *parser,
const char *header_field_mark = 0;
const char *header_value_mark = 0;
const char *url_mark = 0;
const char *reason_mark = 0;

if (state == s_header_field)
header_field_mark = data;
Expand Down Expand Up @@ -629,16 +630,16 @@ size_t http_parser_execute (http_parser *parser,
}

case s_res_status:
/* the human readable status. e.g. "NOT FOUND"
* we are not humans so just ignore this */
if (ch == CR) {
state = s_res_line_almost_done;
break;
}

if (ch == LF) {
state = s_header_field_start;
break;
switch (ch) {
case CR:
state = s_res_line_almost_done;
break;
case LF:
state = s_header_field_start;
break;
default:
CALLBACK(reason);
break;
}
break;

Expand Down
2 changes: 2 additions & 0 deletions http_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ enum flags
XX(CB_path, "the on_path callback failed") \
XX(CB_query_string, "the on_query_string callback failed") \
XX(CB_url, "the on_url callback failed") \
XX(CB_reason, "the on_reason callback failed") \
XX(CB_fragment, "the on_fragment callback failed") \
XX(CB_header_field, "the on_header_field callback failed") \
XX(CB_header_value, "the on_header_value callback failed") \
Expand Down Expand Up @@ -236,6 +237,7 @@ struct http_parser {
struct http_parser_settings {
http_cb on_message_begin;
http_data_cb on_url;
http_data_cb on_reason;
http_data_cb on_header_field;
http_data_cb on_header_value;
http_cb on_headers_complete;
Expand Down

0 comments on commit 3b75bc1

Please sign in to comment.