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:
parent
221e801307
commit
50891b21f2
3 changed files with 21 additions and 7 deletions
|
|
@ -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')
|
||||
return ERR_HTTP_INVALID_INPUT;
|
||||
|
||||
// Trim trailing \r
|
||||
if ((*res)->size > 0 && (*res)->data[(*res)->size - 1] == '\r')
|
||||
{
|
||||
(*res)->size--;
|
||||
}
|
||||
|
||||
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
|
||||
// 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)
|
||||
{
|
||||
|
|
@ -87,9 +94,9 @@ ssize_t parse_headers(struct http_request *res, struct string *req,
|
|||
i += nread + 1;
|
||||
}
|
||||
|
||||
if (req->data[i] == '\r')
|
||||
if (i < req->size && req->data[i] == '\r')
|
||||
i++;
|
||||
if (req->data[i] == '\n')
|
||||
if (i < req->size && req->data[i] == '\n')
|
||||
i++;
|
||||
|
||||
return i;
|
||||
|
|
|
|||
|
|
@ -68,9 +68,15 @@ static ssize_t parse_reqline(struct http_request *res, struct string *req)
|
|||
return ERR_HTTP_INVALID_INPUT;
|
||||
i += skipped;
|
||||
|
||||
// CRLF (EOL)
|
||||
if (req->data[i++] != '\r' && req->data[i++] != '\n')
|
||||
// CRLF (EOL) oh qu'il est casse couilles celui-là
|
||||
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;
|
||||
i++;
|
||||
// Donc 2h de debug pour ça là ? Plutot envie de me tirer une balle si vous
|
||||
// voulez mon avis
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
@ -184,7 +190,8 @@ static void check_req(struct http_request *req, struct http_response *resp)
|
|||
!= 0)
|
||||
resp->status_code = 400;
|
||||
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;
|
||||
|
||||
// Host
|
||||
|
|
@ -195,7 +202,7 @@ static void check_req(struct http_request *req, struct http_response *resp)
|
|||
while (cur != NULL)
|
||||
{
|
||||
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++;
|
||||
if (cur->value == NULL || cur->value->size == 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue