Fix http parser bugs
This commit is contained in:
@@ -156,7 +156,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
|
|||||||
|
|
||||||
conf = get_host_config(host);
|
conf = get_host_config(host);
|
||||||
if (conf == NULL) {
|
if (conf == NULL) {
|
||||||
print("Host unknown, redirecting to default");
|
print("Unknown host, redirecting to default");
|
||||||
res.status = http_get_status(307);
|
res.status = http_get_status(307);
|
||||||
sprintf(buf0, "https://%s%s", DEFAULT_HOST, req.uri);
|
sprintf(buf0, "https://%s%s", DEFAULT_HOST, req.uri);
|
||||||
http_add_header_field(&res.hdr, "Location", buf0);
|
http_add_header_field(&res.hdr, "Location", buf0);
|
||||||
|
@@ -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);
|
print(ERR_STR "Unable to parse header" CLR_STR);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
long len1 = pos1 - buf - 1;
|
long len1 = pos1 - buf;
|
||||||
|
|
||||||
pos1++;
|
pos1++;
|
||||||
str_trim_lws(&pos1, &pos2);
|
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) {
|
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];
|
char field_name_1[256], field_name_2[256];
|
||||||
memcpy(field_name_1, field_name, len);
|
memcpy(field_name_1, field_name, len);
|
||||||
|
field_name_1[len] = 0;
|
||||||
http_to_camel_case(field_name_1, HTTP_LOWER);
|
http_to_camel_case(field_name_1, HTTP_LOWER);
|
||||||
|
|
||||||
for (int i = 0; i < hdr->field_num; i++) {
|
for (int i = 0; i < hdr->field_num; i++) {
|
||||||
strcpy(field_name_2, http_field_get_name(&hdr->fields[i]));
|
strcpy(field_name_2, http_field_get_name(&hdr->fields[i]));
|
||||||
http_to_camel_case(field_name_2, HTTP_LOWER);
|
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 i;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user