Skip to content

Commit 43bdb52

Browse files
committed
src: handle Upgrade: without Conn: upgrade
In strict mode this should not be treated as upgrade, in normal mode we should be gentle and allow it. Fix: nodejs#217
1 parent 5d414fc commit 43bdb52

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎http_parser.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,10 +1790,15 @@ size_t http_parser_execute (http_parser *parser,
17901790
UPDATE_STATE(s_headers_done);
17911791

17921792
/* Set this here so that on_headers_complete() callbacks can see it */
1793+
#if HTTP_PARSER_STRICT
17931794
parser->upgrade =
17941795
((parser->flags & (F_UPGRADE | F_CONNECTION_UPGRADE)) ==
17951796
(F_UPGRADE | F_CONNECTION_UPGRADE) ||
17961797
parser->method == HTTP_CONNECT);
1798+
#else
1799+
parser->upgrade = (parser->flags & F_UPGRADE) ||
1800+
parser->method == HTTP_CONNECT;
1801+
#endif
17971802

17981803
/* Here we call the headers_complete callback. This is somewhat
17991804
* different than other callbacks because if the user returns 1, we

‎test.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,30 @@ const struct message requests[] =
10361036
,.body= ""
10371037
}
10381038

1039+
#if !HTTP_PARSER_STRICT
1040+
#define CONNECTION_UPGRADE_REGRESSION 38
1041+
, {.name = "upgrade header with some random words"
1042+
,.type= HTTP_REQUEST
1043+
,.raw= "GET / HTTP/1.1\r\n"
1044+
"Upgrade: Yes, please.\r\n"
1045+
"\r\n"
1046+
,.should_keep_alive= TRUE
1047+
,.message_complete_on_eof= FALSE
1048+
,.http_major= 1
1049+
,.http_minor= 1
1050+
,.method= HTTP_GET
1051+
,.query_string= ""
1052+
,.fragment= ""
1053+
,.request_path= "/"
1054+
,.request_url= "/"
1055+
,.num_headers= 1
1056+
,.upgrade=""
1057+
,.headers= { { "Upgrade", "Yes, please." }
1058+
}
1059+
,.body= ""
1060+
}
1061+
#endif
1062+
10391063
, {.name= NULL } /* sentinel */
10401064
};
10411065

0 commit comments

Comments
 (0)