From 81b5a569db41971798c48d73a2848e878929c34c Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 12 Dec 2020 22:02:49 +0100 Subject: [PATCH] Fix in http_receive_request --- src/client.c | 1 + src/net/http.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/client.c b/src/client.c index 02b8781..b843e74 100644 --- a/src/client.c +++ b/src/client.c @@ -68,6 +68,7 @@ int client_request_handler(sock *client, int req_num) { client_keep_alive = hdr_connection != NULL && strncmp(hdr_connection, "keep-alive", 10) == 0; host = http_get_header_field(&req.hdr, "Host"); if (host == NULL) { + res.status = http_get_status(400); goto respond; } diff --git a/src/net/http.c b/src/net/http.c index 1543bb2..c7e08e1 100644 --- a/src/net/http.c +++ b/src/net/http.c @@ -70,18 +70,15 @@ int http_receive_request(sock *client, http_req *req) { } ptr = buf; - while (rcv_len - (ptr - buf) != 0) { + while (rcv_len != (ptr - buf)) { pos0 = memchr(ptr, '\r', rcv_len - (ptr - buf)); if (pos0 == NULL || pos0[1] != '\n') { print(ERR_STR "Unable to parse header: Invalid header format" CLR_STR); free(buf); return -1; - } else if (pos0[2] == '\r' && pos0[3] == '\n') { - free(buf); - return 0; } - if (ptr == buf) { + if (req->version[0] == 0) { if (memcmp(ptr, "GET ", 4) == 0) { sprintf(req->method, "GET"); } else if (memcmp(ptr, "HEAD ", 5) == 0) { @@ -147,7 +144,10 @@ int http_receive_request(sock *client, http_req *req) { req->hdr.field_num++; } - + if (pos0[2] == '\r' && pos0[3] == '\n') { + free(buf); + return 0; + } ptr = pos0 + 2; } }