Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
API CHANGE: Remove path, query, fragment CBs.
Browse files Browse the repository at this point in the history
- Get rid of support for these callbacks in http_parser_settings.
- Retain state transitions between different URL portions in
  http_parser_execute() so that we're making the same correctness
  guarantees as before.
- These are being removed because making multiple callbacks for the same
  byte makes it more difficult to pause the parser.
  • Loading branch information
pgriess committed Jul 20, 2011
1 parent 49faf2e commit 53adfac
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 159 deletions.
30 changes: 0 additions & 30 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,12 @@ size_t http_parser_execute (http_parser *parser,
separated. */
const char *header_field_mark = 0;
const char *header_value_mark = 0;
const char *fragment_mark = 0;
const char *query_string_mark = 0;
const char *path_mark = 0;
const char *url_mark = 0;

if (state == s_header_field)
header_field_mark = data;
if (state == s_header_value)
header_value_mark = data;
if (state == s_req_fragment)
fragment_mark = data;
if (state == s_req_query_string)
query_string_mark = data;
if (state == s_req_path)
path_mark = data;
if (state == s_req_path || state == s_req_schema || state == s_req_schema_slash
|| state == s_req_schema_slash_slash || state == s_req_port
|| state == s_req_query_string_start || state == s_req_query_string
Expand Down Expand Up @@ -757,7 +748,6 @@ size_t http_parser_execute (http_parser *parser,

if (ch == '/' || ch == '*') {
MARK(url);
MARK(path);
state = s_req_path;
break;
}
Expand Down Expand Up @@ -807,7 +797,6 @@ size_t http_parser_execute (http_parser *parser,
state = s_req_port;
break;
case '/':
MARK(path);
state = s_req_path;
break;
case ' ':
Expand All @@ -833,7 +822,6 @@ size_t http_parser_execute (http_parser *parser,
if (IS_NUM(ch)) break;
switch (ch) {
case '/':
MARK(path);
state = s_req_path;
break;
case ' ':
Expand Down Expand Up @@ -861,29 +849,24 @@ size_t http_parser_execute (http_parser *parser,
switch (ch) {
case ' ':
CALLBACK(url);
CALLBACK(path);
state = s_req_http_start;
break;
case CR:
CALLBACK(url);
CALLBACK(path);
parser->http_major = 0;
parser->http_minor = 9;
state = s_req_line_almost_done;
break;
case LF:
CALLBACK(url);
CALLBACK(path);
parser->http_major = 0;
parser->http_minor = 9;
state = s_header_field_start;
break;
case '?':
CALLBACK(path);
state = s_req_query_string_start;
break;
case '#':
CALLBACK(path);
state = s_req_fragment_start;
break;
default:
Expand All @@ -896,7 +879,6 @@ size_t http_parser_execute (http_parser *parser,
case s_req_query_string_start:
{
if (IS_URL_CHAR(ch)) {
MARK(query_string);
state = s_req_query_string;
break;
}
Expand Down Expand Up @@ -940,25 +922,21 @@ size_t http_parser_execute (http_parser *parser,
break;
case ' ':
CALLBACK(url);
CALLBACK(query_string);
state = s_req_http_start;
break;
case CR:
CALLBACK(url);
CALLBACK(query_string);
parser->http_major = 0;
parser->http_minor = 9;
state = s_req_line_almost_done;
break;
case LF:
CALLBACK(url);
CALLBACK(query_string);
parser->http_major = 0;
parser->http_minor = 9;
state = s_header_field_start;
break;
case '#':
CALLBACK(query_string);
state = s_req_fragment_start;
break;
default:
Expand All @@ -971,7 +949,6 @@ size_t http_parser_execute (http_parser *parser,
case s_req_fragment_start:
{
if (IS_URL_CHAR(ch)) {
MARK(fragment);
state = s_req_fragment;
break;
}
Expand All @@ -994,7 +971,6 @@ size_t http_parser_execute (http_parser *parser,
state = s_header_field_start;
break;
case '?':
MARK(fragment);
state = s_req_fragment;
break;
case '#':
Expand All @@ -1013,19 +989,16 @@ size_t http_parser_execute (http_parser *parser,
switch (ch) {
case ' ':
CALLBACK(url);
CALLBACK(fragment);
state = s_req_http_start;
break;
case CR:
CALLBACK(url);
CALLBACK(fragment);
parser->http_major = 0;
parser->http_minor = 9;
state = s_req_line_almost_done;
break;
case LF:
CALLBACK(url);
CALLBACK(fragment);
parser->http_major = 0;
parser->http_minor = 9;
state = s_header_field_start;
Expand Down Expand Up @@ -1733,9 +1706,6 @@ size_t http_parser_execute (http_parser *parser,

CALLBACK(header_field);
CALLBACK(header_value);
CALLBACK(fragment);
CALLBACK(query_string);
CALLBACK(path);
CALLBACK(url);

parser->state = state;
Expand Down
3 changes: 0 additions & 3 deletions http_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ struct http_parser {

struct http_parser_settings {
http_cb on_message_begin;
http_data_cb on_path;
http_data_cb on_query_string;
http_data_cb on_url;
http_data_cb on_fragment;
http_data_cb on_header_field;
http_data_cb on_header_value;
http_cb on_headers_complete;
Expand Down
Loading

3 comments on commit 53adfac

@tj
Copy link

@tj tj commented on 53adfac Jul 20, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it's just request_url now? I'm using the others and wouldn't mind them staying so I dont have to re-parse them in c land, but it's not a show stopper I guess, pretty simple to delimit

@pgriess
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's just request_url now. Check out the discussion on this pull request for the justification at ry/http-parser#54.

What were you using the callbacks for? If this is node-land, can you just use the the 'url' module to parse what you want?

@tj
Copy link

@tj tj commented on 53adfac Jul 20, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah it's a none-node related C project, thanks I'll check it out!

Please sign in to comment.