summaryrefslogtreecommitdiff
path: root/ext/http-parser/http_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/http-parser/http_parser.c')
-rw-r--r--ext/http-parser/http_parser.c121
1 files changed, 38 insertions, 83 deletions
diff --git a/ext/http-parser/http_parser.c b/ext/http-parser/http_parser.c
index a113c7f5..3c896ffa 100644
--- a/ext/http-parser/http_parser.c
+++ b/ext/http-parser/http_parser.c
@@ -123,7 +123,7 @@ do { \
FOR##_mark = NULL; \
} \
} while (0)
-
+
/* Run the data callback FOR and consume the current byte */
#define CALLBACK_DATA(FOR) \
CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1)
@@ -440,7 +440,7 @@ enum http_host_state
* character or %x80-FF
**/
#define IS_HEADER_CHAR(ch) \
- (ch == CR || ch == LF || ch == 9 || (ch > 31 && ch != 127))
+ (ch == CR || ch == LF || ch == 9 || ((unsigned char)ch > 31 && ch != 127))
#define start_state (parser->type == HTTP_REQUEST ? s_start_req : s_start_res)
@@ -1007,89 +1007,40 @@ reexecute:
UPDATE_STATE(s_req_spaces_before_url);
} else if (ch == matcher[parser->index]) {
; /* nada */
- } else if (parser->method == HTTP_CONNECT) {
- if (parser->index == 1 && ch == 'H') {
- parser->method = HTTP_CHECKOUT;
- } else if (parser->index == 2 && ch == 'P') {
- parser->method = HTTP_COPY;
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
- }
- } else if (parser->method == HTTP_MKCOL) {
- if (parser->index == 1 && ch == 'O') {
- parser->method = HTTP_MOVE;
- } else if (parser->index == 1 && ch == 'E') {
- parser->method = HTTP_MERGE;
- } else if (parser->index == 1 && ch == '-') {
- parser->method = HTTP_MSEARCH;
- } else if (parser->index == 2 && ch == 'A') {
- parser->method = HTTP_MKACTIVITY;
- } else if (parser->index == 3 && ch == 'A') {
- parser->method = HTTP_MKCALENDAR;
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
- }
- } else if (parser->method == HTTP_SUBSCRIBE) {
- if (parser->index == 1 && ch == 'E') {
- parser->method = HTTP_SEARCH;
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
- }
- } else if (parser->method == HTTP_REPORT) {
- if (parser->index == 2 && ch == 'B') {
- parser->method = HTTP_REBIND;
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
- }
- } else if (parser->index == 1) {
- if (parser->method == HTTP_POST) {
- if (ch == 'R') {
- parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */
- } else if (ch == 'U') {
- parser->method = HTTP_PUT; /* or HTTP_PURGE */
- } else if (ch == 'A') {
- parser->method = HTTP_PATCH;
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
- }
- } else if (parser->method == HTTP_LOCK) {
- if (ch == 'I') {
- parser->method = HTTP_LINK;
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
- }
- }
- } else if (parser->index == 2) {
- if (parser->method == HTTP_PUT) {
- if (ch == 'R') {
- parser->method = HTTP_PURGE;
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
- }
- } else if (parser->method == HTTP_UNLOCK) {
- if (ch == 'S') {
- parser->method = HTTP_UNSUBSCRIBE;
- } else if(ch == 'B') {
- parser->method = HTTP_UNBIND;
- } else {
+ } else if (IS_ALPHA(ch)) {
+
+ switch (parser->method << 16 | parser->index << 8 | ch) {
+#define XX(meth, pos, ch, new_meth) \
+ case (HTTP_##meth << 16 | pos << 8 | ch): \
+ parser->method = HTTP_##new_meth; break;
+
+ XX(POST, 1, 'U', PUT)
+ XX(POST, 1, 'A', PATCH)
+ XX(CONNECT, 1, 'H', CHECKOUT)
+ XX(CONNECT, 2, 'P', COPY)
+ XX(MKCOL, 1, 'O', MOVE)
+ XX(MKCOL, 1, 'E', MERGE)
+ XX(MKCOL, 2, 'A', MKACTIVITY)
+ XX(MKCOL, 3, 'A', MKCALENDAR)
+ XX(SUBSCRIBE, 1, 'E', SEARCH)
+ XX(REPORT, 2, 'B', REBIND)
+ XX(POST, 1, 'R', PROPFIND)
+ XX(PROPFIND, 4, 'P', PROPPATCH)
+ XX(PUT, 2, 'R', PURGE)
+ XX(LOCK, 1, 'I', LINK)
+ XX(UNLOCK, 2, 'S', UNSUBSCRIBE)
+ XX(UNLOCK, 2, 'B', UNBIND)
+ XX(UNLOCK, 3, 'I', UNLINK)
+#undef XX
+
+ default:
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
- }
- } else {
- SET_ERRNO(HPE_INVALID_METHOD);
- goto error;
}
- } else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') {
- parser->method = HTTP_PROPPATCH;
- } else if (parser->index == 3 && parser->method == HTTP_UNLOCK && ch == 'I') {
- parser->method = HTTP_UNLINK;
+ } else if (ch == '-' &&
+ parser->index == 1 &&
+ parser->method == HTTP_MKCOL) {
+ parser->method = HTTP_MSEARCH;
} else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
@@ -1861,6 +1812,9 @@ reexecute:
case 0:
break;
+ case 2:
+ parser->upgrade = 1;
+
case 1:
parser->flags |= F_SKIPBODY;
break;
@@ -2299,12 +2253,13 @@ http_parse_host_char(enum http_host_state s, const char ch) {
static int
http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
- //assert(u->field_set & (1 << UF_HOST));
enum http_host_state s;
const char *p;
size_t buflen = u->field_data[UF_HOST].off + u->field_data[UF_HOST].len;
+ assert(u->field_set & (1 << UF_HOST));
+
u->field_data[UF_HOST].len = 0;
s = found_at ? s_http_userinfo_start : s_http_host_start;