Browse Source

Upgrade http-parser

Fixes \n problem that psanford <pms.mail@gmail.com> reported.
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
75e6c39733
  1. 20
      deps/http_parser/http_parser.c
  2. 22
      deps/http_parser/http_parser.h
  3. 24
      deps/http_parser/test.c

20
deps/http_parser/http_parser.c

@ -198,7 +198,6 @@ enum state
, s_header_almost_done , s_header_almost_done
, s_headers_almost_done , s_headers_almost_done
, s_headers_done
, s_chunk_size_start , s_chunk_size_start
, s_chunk_size , s_chunk_size
@ -236,10 +235,10 @@ enum header_states
}; };
enum flags enum flags
{ F_CHUNKED = 0x0001 { F_CHUNKED = 1 << 0
, F_CONNECTION_KEEP_ALIVE = 0x0002 , F_CONNECTION_KEEP_ALIVE = 1 << 1
, F_CONNECTION_CLOSE = 0x0004 , F_CONNECTION_CLOSE = 1 << 2
, F_TRAILING = 0x0010 , F_TRAILING = 1 << 3
}; };
#define CR '\r' #define CR '\r'
@ -931,8 +930,10 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
} }
if (ch == LF) { if (ch == LF) {
state = s_headers_done; /* they might be just sending \n instead of \r\n so this would be
break; * the second \n to denote the end of headers*/
state = s_headers_almost_done;
goto headers_almost_done;
} }
c = LOWER(ch); c = LOWER(ch);
@ -1138,8 +1139,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
if (ch == LF) { if (ch == LF) {
CALLBACK(header_value); CALLBACK(header_value);
state = s_header_field_start; goto header_almost_done;
break;
} }
break; break;
} }
@ -1206,6 +1206,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
} }
case s_header_almost_done: case s_header_almost_done:
header_almost_done:
{ {
STRICT_CHECK(ch != LF); STRICT_CHECK(ch != LF);
@ -1228,6 +1229,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
} }
case s_headers_almost_done: case s_headers_almost_done:
headers_almost_done:
{ {
STRICT_CHECK(ch != LF); STRICT_CHECK(ch != LF);

22
deps/http_parser/http_parser.h

@ -135,28 +135,6 @@ size_t http_parse_responses(http_parser *parser, const char *data, size_t len);
*/ */
int http_should_keep_alive(http_parser *parser); int http_should_keep_alive(http_parser *parser);
static inline const char * http_method_str (enum http_method method)
{
switch (method) {
case HTTP_DELETE: return "DELETE";
case HTTP_GET: return "GET";
case HTTP_HEAD: return "HEAD";
case HTTP_POST: return "POST";
case HTTP_PUT: return "PUT";
case HTTP_CONNECT: return "CONNECT";
case HTTP_OPTIONS: return "OPTIONS";
case HTTP_TRACE: return "TRACE";
case HTTP_COPY: return "COPY";
case HTTP_LOCK: return "LOCK";
case HTTP_MKCOL: return "MKCOL";
case HTTP_MOVE: return "MOVE";
case HTTP_PROPFIND: return "PROPFIND";
case HTTP_PROPPATCH: return "PROPPATCH";
case HTTP_UNLOCK: return "UNLOCK";
default: return (const char*)0;
}
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

24
deps/http_parser/test.c

@ -579,6 +579,27 @@ const struct message responses[] =
} }
#define NO_CARRIAGE_RET 5
, {.name="no carriage ret"
,.type= RESPONSE
,.raw= "HTTP/1.1 200 OK\n"
"Content-Type: text/html; charset=utf-8\n"
"Connection: close\n"
"\n"
"these headers are from http://news.ycombinator.com/"
,.should_keep_alive= FALSE
,.message_complete_on_eof= TRUE
,.http_major= 1
,.http_minor= 1
,.status_code= 200
,.num_headers= 2
,.headers=
{ {"Content-Type", "text/html; charset=utf-8" }
, {"Connection", "close" }
}
,.body= "these headers are from http://news.ycombinator.com/"
}
, {.name= NULL } /* sentinel */ , {.name= NULL } /* sentinel */
}; };
@ -1049,9 +1070,6 @@ main (void)
printf("sizeof(http_parser) = %d\n", sizeof(http_parser)); printf("sizeof(http_parser) = %d\n", sizeof(http_parser));
assert(strcmp(http_method_str(HTTP_GET), "GET") == 0);
assert(strcmp(http_method_str(HTTP_CONNECT), "CONNECT") == 0);
for (request_count = 0; requests[request_count].name; request_count++); for (request_count = 0; requests[request_count].name; request_count++);
for (response_count = 0; responses[response_count].name; response_count++); for (response_count = 0; responses[response_count].name; response_count++);

Loading…
Cancel
Save