Fix #2790 - allow tabs as the HTTP header whitespace

This commit is contained in:
Sergey Lyubka committed 2024-06-17 12:01:32 +01:00
1 parent 8fd7e87333
commit f9bcffcbd5
3 files changed
+30 -6

No files matched your search

+20
View File
@@ -868,6 +868,10 @@ static void test_http_server(void) {
ASSERT(cmpbody(buf, "hello\n") == 0);
ASSERT(cmpheader(buf, "C", "D"));
ASSERT(fetch(&mgr, buf, url, "GET /a.txt HTTP/1.0\nA:\tB\n\n") == 200);
ASSERT(cmpbody(buf, "hello\n") == 0);
ASSERT(cmpheader(buf, "C", "D"));
// Invalid header: failure
ASSERT(fetch(&mgr, buf, url, "GET /a.txt HTTP/1.0\nA B\n\n") == 0);
@@ -1613,6 +1617,22 @@ static void test_http_parse(void) {
s = "a b\n\xc0: 2\n\n"; // Invalid UTF in the header name: do NOT accept
ASSERT(mg_http_parse(s, strlen(s), &hm) == -1);
}
{
struct mg_http_message hm;
const char *s;
s = "a b c\nd:e\n\n";
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
s = "a b c\nd: e\n\n";
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
s = "a b c\nd:\te\n\n";
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
s = "a b c\nd:\t e\n\n";
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
s = "a b c\nd: \te\t \n\n";
ASSERT(mg_http_parse(s, strlen(s), &hm) == (int) strlen(s));
ASSERT(mg_strcmp(hm.headers[0].value, mg_str("e")) == 0);
}
}
static void ehr(struct mg_connection *c, int ev, void *ev_data) {