LibHTTP: Correctly normalize header whitespace in cache utilities
We also shouldn't trim whitespace at all when reading headers from the cache index. We store them as-is and should therefore read them as-is.
This commit is contained in:
parent
0652a33043
commit
ef134c940e
4 changed files with 29 additions and 4 deletions
|
|
@ -38,11 +38,11 @@ static NonnullRefPtr<HeaderList> deserialize_headers(StringView serialized_heade
|
|||
if (!index.has_value())
|
||||
return;
|
||||
|
||||
auto name = serialized_header.substring_view(0, *index).trim_whitespace();
|
||||
auto name = serialized_header.substring_view(0, *index);
|
||||
if (is_header_exempted_from_storage(name))
|
||||
return;
|
||||
|
||||
auto value = serialized_header.substring_view(*index + 1).trim_whitespace();
|
||||
auto value = serialized_header.substring_view(*index + 1);
|
||||
headers->append({ name, value });
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -643,7 +643,7 @@ ByteString normalize_request_vary_header_values(StringView header, HeaderList co
|
|||
}
|
||||
|
||||
value.view().for_each_split_view(","sv, SplitBehavior::Nothing, [&](StringView field) {
|
||||
values.append(field.trim_whitespace());
|
||||
values.append(normalize_header_value(field));
|
||||
});
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public:
|
|||
IterationDecision result;
|
||||
|
||||
value.for_each_split_view(","sv, SplitBehavior::Nothing, [&](StringView header) -> IterationDecision {
|
||||
result = callback(header.trim_whitespace());
|
||||
result = callback(normalize_header_value(header));
|
||||
return result;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -955,6 +955,31 @@
|
|||
expectCacheStatus(url, response, "read-from-cache");
|
||||
})();
|
||||
|
||||
// Requsts with a Vary header with improper whitespace do not match normal response headers.
|
||||
await (async () => {
|
||||
url = await createRequest("/cache-test/vary/vertical-tab", {
|
||||
headers: {
|
||||
"Cache-Control": "max-age=10",
|
||||
Vary: "Accept\v",
|
||||
},
|
||||
});
|
||||
|
||||
response = await cacheFetch(url, {
|
||||
headers: {
|
||||
Accept: "text/html",
|
||||
},
|
||||
});
|
||||
expectCacheStatus(url, response, "written-to-cache");
|
||||
|
||||
// This would normally be a Vary mismatch, but "Accept\v" does not match "Accept".
|
||||
response = await cacheFetch(url, {
|
||||
headers: {
|
||||
Accept: "text/javascript",
|
||||
},
|
||||
});
|
||||
expectCacheStatus(url, response, "read-from-cache");
|
||||
})();
|
||||
|
||||
// Responses with a Vary header that matches subsequent request headers after normalization may be used.
|
||||
await (async () => {
|
||||
url = await createRequest("/cache-test/vary/normalization", {
|
||||
|
|
|
|||
Loading…
Reference in a new issue