Make header parsing case insensitive.

This makes darkhttpd more useful behind an HTTP2 reverse proxy,
because the HTTP2 headers are all lowercase.

Suggested by: @Hill-98

Fixes #15
This commit is contained in:
Emil Mikulic 2022-01-19 20:01:32 +11:00
parent 1759a7a7d9
commit f0ca481fd1
2 changed files with 7 additions and 2 deletions

View File

@ -1600,7 +1600,7 @@ static void redirect(struct connection *conn, const char *format, ...) {
/* Parses a single HTTP request field. Returns string from end of [field] to
* first \r, \n or end of request string. Returns NULL if [field] can't be
* matched.
* matched. Case insensitive.
*
* You need to remember to deallocate the result.
* example: parse_field(conn, "Referer: ");
@ -1610,7 +1610,7 @@ static char *parse_field(const struct connection *conn, const char *field) {
char *pos;
/* find start */
pos = strstr(conn->request, field);
pos = strcasestr(conn->request, field);
if (pos == NULL)
return NULL;
assert(pos >= conn->request);

View File

@ -385,6 +385,11 @@ class TestFileGet(TestHelper):
status, hdrs, body = parse(resp)
self.assertContains(status, "416 Requested Range Not Satisfiable")
def test_lowercase_header(self):
resp = self.get(self.url, req_hdrs = {"range": "bytes=20-10"})
status, hdrs, body = parse(resp)
self.assertContains(status, "416 Requested Range Not Satisfiable")
class TestKeepAlive(TestFileGet):
"""
Run all of TestFileGet but with a single long-lived connection.