Browse files

Add on_status_complete callback.

Add a "status complete" callback to support Simple-Response handling with HTTP
version <= 1.0.

Patch by Tóth Tamás, tests by Corey Richardson.
  • Loading branch information...
1 parent 798eb90 commit 0938fe599f7e3e4405880216ea445d634a974375 @tomika tomika committed with bnoordhuis Mar 24, 2012
Showing with 26 additions and 0 deletions.
  1. +1 −0 http_parser.c
  2. +2 −0 http_parser.h
  3. +23 −0 test.c
1 http_parser.c
@@ -866,6 +866,7 @@ size_t http_parser_execute (http_parser *parser,
case s_res_line_almost_done:
parser->state = s_header_field_start;
+ CALLBACK_NOTIFY(status_complete);
case s_start_req:
2 http_parser.h
@@ -141,6 +141,7 @@ enum flags
/* Callback-related errors */ \
XX(CB_message_begin, "the on_message_begin callback failed") \
+ XX(CB_status_complete, "the on_status_complete callback failed") \
XX(CB_url, "the on_url callback failed") \
XX(CB_header_field, "the on_header_field callback failed") \
XX(CB_header_value, "the on_header_value callback failed") \
@@ -221,6 +222,7 @@ struct http_parser {
struct http_parser_settings {
http_cb on_message_begin;
http_data_cb on_url;
+ http_cb on_status_complete;
http_data_cb on_header_field;
http_data_cb on_header_value;
http_cb on_headers_complete;
23 test.c
@@ -1492,6 +1492,13 @@ request_url_cb (http_parser *p, const char *buf, size_t len)
+status_complete_cb (http_parser *p) {
+ assert(p == parser);
+ p->data++;
+ return 0;
header_field_cb (http_parser *p, const char *buf, size_t len)
assert(p == parser);
@@ -3089,6 +3096,20 @@ create_large_chunked_message (int body_size_in_kb, const char* headers)
return buf;
+test_status_complete (void)
+ parser_init(HTTP_RESPONSE);
+ parser->data = 0;
+ http_parser_settings settings = settings_null;
+ settings.on_status_complete = status_complete_cb;
+ char *response = "don't mind me, just a simple response";
+ http_parser_execute(parser, &settings, response, strlen(response));
+ assert(parser->data == (void*)0); // the status_complete callback was never called
+ assert(parser->http_errno == HPE_INVALID_CONSTANT); // the errno for an invalid status line
/* Verify that we can pause parsing at any of the bytes in the
* message and still get the result that we're expecting. */
@@ -3396,6 +3417,8 @@ main (void)
, &requests[CONNECT_REQUEST]
+ test_status_complete();
puts("requests okay");
return 0;

7 comments on commit 0938fe5


Adding the status_complete on the header and c files breaks my program.
It doesn't parse the HTTP_RESPONSE header correctly.
However this only breaks when I compiled it on my Debian server.
It works fine on my mac and ubuntu.

What is the status_complete is for?
any thoughts on what side effects it introduces?

Node.js Foundation member

What is the status_complete is for?

To deal with HTTP/0.9 responses.

"breaks my program" is a little vague but I'm guessing it's an ABI issue. Do a clean rebuild of http_parser and your project.


I forgot to mention that I run this inside node addons.
Is there some quirks on running http-parser inside addons?
Here is the steps to reproduce:


If I run it without addons, it works fine.
I'm wondering whether it is the bug inside addons?
Or maybe a combination of addons + http-parser bug.
See for the code without addons ( )

Node.js Foundation member

node.js ships an older http_parser version. If you build your add-on against a newer version, you need to link that newer version statically against your add-on or bad things will happen.


I see, that is why I encountered weird things like: I edit http_parser.c, the node-gyp did compile what I edited, but it does NOT use it :(. So yes I am guessing it links to the "old" internal node.js http_parser.

Ok, how to statically link my add-on to the newest version that I cloned?
What should I write in the binding.gyp? Definitely my current binding.gyp is not correct?:


Node.js Foundation member

Bundle http_parser with your add-on and declare it as a dependency in your gyp file.

Please sign in to comment.