Skip to content

Commit

Permalink
case-insensitive headers
Browse files Browse the repository at this point in the history
  • Loading branch information
DaseinPhaos committed Aug 14, 2024
1 parent 2dd2356 commit 4d3fd23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions linux.jai
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,12 @@ read_http_request :: (socket: Socket, thread_id: s32) -> *Request {
kv := split(line, ": ");
#if parseheaders table_add(*request.headers, kv[0], kv[1]);

if kv[0] == {
case "Content-Length"; request.content_length = xx to_integer(kv[1]);
case "Sec-WebSocket-Key"; request.websocket_key = kv[1];
case "Accept-Encoding"; request.accept_encoding = kv[1];
if compare_nocase(kv[0], "Content-Length") == 0 {
request.content_length = xx to_integer(kv[1]);
} else if compare_nocase(kv[0], "Sec-WebSocket-Key") == 0 {
request.websocket_key = kv[1];
} else if compare_nocase(kv[0], "Accept-Encoding") == 0 {
request.accept_encoding = kv[1];
}

if request.raw[request.buffercursor+2] == #char "\r" && request.raw[request.buffercursor+2 + 1] == #char "\n" {
Expand Down
9 changes: 6 additions & 3 deletions windows.jai
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,12 @@ recv_http_request :: (socket: MySocket) -> Request {
kv := split(line, ": ");
#if parseheaders table_add(*request.headers, kv[0], kv[1]);

if kv[0] == {
case "Content-Length"; request.content_length = xx to_integer(kv[1]);
case "Sec-WebSocket-Key"; request.websocket_key = kv[1];
if compare_nocase(kv[0], "Content-Length") == 0 {
request.content_length = xx to_integer(kv[1]);
} else if compare_nocase(kv[0], "Sec-WebSocket-Key") == 0 {
request.websocket_key = kv[1];
} else if compare_nocase(kv[0], "Accept-Encoding") == 0 {
request.accept_encoding = kv[1];
}

if request.raw[buffercursor+2] == #char "\r" && request.raw[buffercursor+2 + 1] == #char "\n" {
Expand Down

0 comments on commit 4d3fd23

Please sign in to comment.