Browse Source

[core] replace folding whitespace with a single space

- previously the leading whitespace from folded lines was kept
- also ignore lines without any data
personal/stbuehler/fix-fdevent
Stefan Bühler 4 years ago
parent
commit
3be0707839
  1. 13
      src/request.c
  2. 8
      src/t/test_request.c

13
src/request.c

@ -1067,7 +1067,18 @@ int http_request_parse(server *srv, connection *con) {
goto failure;
}
buffer_append_string_len(current_header->value, value, value_len);
if (value_len > 0) {
/* strip leading whitespace; trailing was already removed, so can't be empty */
while (value_len > 0 && (value[0] == ' ' || value[0] == '\t')) {
value++;
--value_len;
}
if (buffer_string_length(current_header->value) > 0) {
buffer_append_string_len(current_header->value, CONST_STR_LEN(" "));
}
buffer_append_string_len(current_header->value, value, value_len);
}
} else {
/* process previous header */
if (current_header) {

8
src/t/test_request.c

@ -229,7 +229,7 @@ static void test_request_http_request_parse(server *srv, connection *con)
array_get_element_klen(con->request.headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(ds->value,
CONST_STR_LEN("foo, foobar baz")));
CONST_STR_LEN("foo, foobar baz")));
run_http_request_parse(srv, con, __LINE__, 0,
"#1232 - duplicate headers with line-wrapping - test 2",
@ -241,7 +241,7 @@ static void test_request_http_request_parse(server *srv, connection *con)
ds = (data_string *)
array_get_element_klen(con->request.headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(ds->value, CONST_STR_LEN("foobar baz")));
&& buffer_is_equal_string(ds->value, CONST_STR_LEN("foobar baz")));
run_http_request_parse(srv, con, __LINE__, 0,
"#1232 - duplicate headers with line-wrapping - test 3",
@ -253,7 +253,7 @@ static void test_request_http_request_parse(server *srv, connection *con)
ds = (data_string *)
array_get_element_klen(con->request.headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(ds->value, CONST_STR_LEN("foobar baz")));
&& buffer_is_equal_string(ds->value, CONST_STR_LEN("foobar baz")));
run_http_request_parse(srv, con, __LINE__, 400,
"missing protocol",
@ -343,7 +343,7 @@ static void test_request_http_request_parse(server *srv, connection *con)
"\r\n"));
ds = (data_string *)
array_get_element_klen(con->request.headers, CONST_STR_LEN("ABC"));
assert(ds && buffer_is_equal_string(ds->value, CONST_STR_LEN("foo bc")));
assert(ds && buffer_is_equal_string(ds->value, CONST_STR_LEN("foo bc")));
run_http_request_parse(srv, con, __LINE__, 411,
"POST request, no Content-Length",

Loading…
Cancel
Save