Fix http parser bugs

This commit is contained in:
2022-08-16 20:04:08 +02:00
parent b6309eec39
commit a738f1abfe
2 changed files with 7 additions and 4 deletions

View File

@ -156,7 +156,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
conf = get_host_config(host);
if (conf == NULL) {
print("Host unknown, redirecting to default");
print("Unknown host, redirecting to default");
res.status = http_get_status(307);
sprintf(buf0, "https://%s%s", DEFAULT_HOST, req.uri);
http_add_header_field(&res.hdr, "Location", buf0);

View File

@ -104,7 +104,7 @@ int http_parse_header_field(http_hdr *hdr, const char *buf, const char *end_ptr)
print(ERR_STR "Unable to parse header" CLR_STR);
return 3;
}
long len1 = pos1 - buf - 1;
long len1 = pos1 - buf;
pos1++;
str_trim_lws(&pos1, &pos2);
@ -235,14 +235,17 @@ int http_get_header_field_num(const http_hdr *hdr, const char *field_name) {
int http_get_header_field_num_len(const http_hdr *hdr, const char *field_name, unsigned long len) {
char field_name_1[256], field_name_2[256];
memcpy(field_name_1, field_name, len);
field_name_1[len] = 0;
http_to_camel_case(field_name_1, HTTP_LOWER);
for (int i = 0; i < hdr->field_num; i++) {
strcpy(field_name_2, http_field_get_name(&hdr->fields[i]));
http_to_camel_case(field_name_2, HTTP_LOWER);
if (strcmp(field_name_1, field_name_2) == 0) {
if (strcmp(field_name_1, field_name_2) == 0)
return i;
}
}
return -1;
}