Bon bah enfin fini de merge les 3 putains de différents repos (beauuucoup trop de temps accordé à ce projet, non mais ouais franchement)

This commit is contained in:
Gu://em_ 2026-01-10 19:05:16 +01:00
parent 221e801307
commit 50891b21f2
3 changed files with 21 additions and 7 deletions

View file

@ -42,6 +42,12 @@ ssize_t read_value(struct string *str, size_t offset, struct string **res)
if (str->size <= offset + nread || str->data[offset + nread] != '\n') if (str->size <= offset + nread || str->data[offset + nread] != '\n')
return ERR_HTTP_INVALID_INPUT; return ERR_HTTP_INVALID_INPUT;
// Trim trailing \r
if ((*res)->size > 0 && (*res)->data[(*res)->size - 1] == '\r')
{
(*res)->size--;
}
return nread; return nread;
} }
@ -53,7 +59,8 @@ ssize_t parse_headers(struct http_request *res, struct string *req,
// Yes I know I do one useless allocation but I really don't care at this // Yes I know I do one useless allocation but I really don't care at this
// point // point
while (req->data[i] != '\n' && req->data[i] != '\r') // ! Blank line while (i < req->size && req->data[i] != '\n'
&& req->data[i] != '\r') // ! Blank line
{ {
if (header == NULL) if (header == NULL)
{ {
@ -87,9 +94,9 @@ ssize_t parse_headers(struct http_request *res, struct string *req,
i += nread + 1; i += nread + 1;
} }
if (req->data[i] == '\r') if (i < req->size && req->data[i] == '\r')
i++; i++;
if (req->data[i] == '\n') if (i < req->size && req->data[i] == '\n')
i++; i++;
return i; return i;

View file

@ -68,9 +68,15 @@ static ssize_t parse_reqline(struct http_request *res, struct string *req)
return ERR_HTTP_INVALID_INPUT; return ERR_HTTP_INVALID_INPUT;
i += skipped; i += skipped;
// CRLF (EOL) // CRLF (EOL) oh qu'il est casse couilles celui-là
if (req->data[i++] != '\r' && req->data[i++] != '\n') ssize_t req_size = req->size; // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah
if (i < req_size && req->data[i] == '\r')
i++;
if (i >= req_size || req->data[i] != '\n')
return ERR_HTTP_INVALID_INPUT; return ERR_HTTP_INVALID_INPUT;
i++;
// Donc 2h de debug pour ça là ? Plutot envie de me tirer une balle si vous
// voulez mon avis
return i; return i;
} }
@ -184,7 +190,8 @@ static void check_req(struct http_request *req, struct http_response *resp)
!= 0) != 0)
resp->status_code = 400; resp->status_code = 400;
else if (string_compare_strictly_n_str(req->protocol, "HTTP/1.1", else if (string_compare_strictly_n_str(req->protocol, "HTTP/1.1",
strlen("HTTP/1.1")) != 0) strlen("HTTP/1.1"))
!= 0)
resp->status_code = 505; resp->status_code = 505;
// Host // Host
@ -195,7 +202,7 @@ static void check_req(struct http_request *req, struct http_response *resp)
while (cur != NULL) while (cur != NULL)
{ {
if (cur->field->size == 4 if (cur->field->size == 4
&& string_compare_n_str(cur->field, "Host", 4) == 0) && string_compare_n_str(cur->field, "host", 4) == 0)
{ {
host_count++; host_count++;
if (cur->value == NULL || cur->value->size == 0) if (cur->value == NULL || cur->value->size == 0)