Commit cb80df61 authored by Aaron Tagliaboschi's avatar Aaron Tagliaboschi Committed by Commit Bot

Make Sec-CH-UA-* headers camel case and quotes

Pretty simple aesthetic changes, but bringing in closer to spec (and
fixing tests to match"

Bug: 959613, 971342
Change-Id: I3a1409a73852a5e767380dbc60d0019847e3fffb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1647436
Commit-Queue: Aaron Tagliaboschi <aarontag@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700256}
parent ad58e1a7
...@@ -182,6 +182,18 @@ mojom::FetchCacheMode DetermineFrameCacheMode(Frame* frame) { ...@@ -182,6 +182,18 @@ mojom::FetchCacheMode DetermineFrameCacheMode(Frame* frame) {
return mojom::FetchCacheMode::kDefault; return mojom::FetchCacheMode::kDefault;
} }
// Simple function to add quotes to make headers strings.
const AtomicString AddQuotes(std::string str) {
if (str.empty())
return AtomicString("");
StringBuilder quoted_string;
quoted_string.Append("\"");
quoted_string.Append(str.data());
quoted_string.Append("\"");
return quoted_string.ToAtomicString();
}
} // namespace } // namespace
struct FrameFetchContext::FrozenState final : GarbageCollected<FrozenState> { struct FrameFetchContext::FrozenState final : GarbageCollected<FrozenState> {
...@@ -525,7 +537,7 @@ void FrameFetchContext::AddClientHintsIfNecessary( ...@@ -525,7 +537,7 @@ void FrameFetchContext::AddClientHintsIfNecessary(
request.SetHttpHeaderField( request.SetHttpHeaderField(
blink::kClientHintsHeaderMapping[static_cast<size_t>( blink::kClientHintsHeaderMapping[static_cast<size_t>(
mojom::WebClientHintsType::kUA)], mojom::WebClientHintsType::kUA)],
result.ToAtomicString()); AddQuotes(result.ToString().Ascii()));
} }
// If the frame is detached, then don't send any hints other than UA. // If the frame is detached, then don't send any hints other than UA.
...@@ -699,7 +711,7 @@ void FrameFetchContext::AddClientHintsIfNecessary( ...@@ -699,7 +711,7 @@ void FrameFetchContext::AddClientHintsIfNecessary(
request.SetHttpHeaderField( request.SetHttpHeaderField(
blink::kClientHintsHeaderMapping[static_cast<size_t>( blink::kClientHintsHeaderMapping[static_cast<size_t>(
mojom::WebClientHintsType::kUAArch)], mojom::WebClientHintsType::kUAArch)],
AtomicString(ua.architecture.data())); AddQuotes(ua.architecture));
} }
if ((can_always_send_hints || if ((can_always_send_hints ||
...@@ -712,7 +724,7 @@ void FrameFetchContext::AddClientHintsIfNecessary( ...@@ -712,7 +724,7 @@ void FrameFetchContext::AddClientHintsIfNecessary(
request.SetHttpHeaderField( request.SetHttpHeaderField(
blink::kClientHintsHeaderMapping[static_cast<size_t>( blink::kClientHintsHeaderMapping[static_cast<size_t>(
mojom::WebClientHintsType::kUAPlatform)], mojom::WebClientHintsType::kUAPlatform)],
AtomicString(ua.platform.data())); AddQuotes(ua.platform));
} }
if ((can_always_send_hints || if ((can_always_send_hints ||
...@@ -725,7 +737,7 @@ void FrameFetchContext::AddClientHintsIfNecessary( ...@@ -725,7 +737,7 @@ void FrameFetchContext::AddClientHintsIfNecessary(
request.SetHttpHeaderField( request.SetHttpHeaderField(
blink::kClientHintsHeaderMapping[static_cast<size_t>( blink::kClientHintsHeaderMapping[static_cast<size_t>(
mojom::WebClientHintsType::kUAModel)], mojom::WebClientHintsType::kUAModel)],
AtomicString(ua.model.data())); AddQuotes(ua.model));
} }
} }
......
def main(request, response):
"""
Simple handler that sets a response header based on which client hint
request headers were received.
"""
response.headers.append("Access-Control-Allow-Origin", "*")
response.headers.append("Access-Control-Allow-Headers", "*")
response.headers.append("Access-Control-Expose-Headers", "*")
client_hint_headers = [
"sec-ch-ua",
"sec-ch-ua-arch",
"sec-ch-ua-platform",
"sec-ch-ua-model",
]
request_client_hints = {i:request.headers.get(i) for i in client_hint_headers}
for header in client_hint_headers:
if request_client_hints[header] is not None:
response.headers.set(header+"-recieved", request_client_hints[header])
headers = []
content = ""
return 200, headers, content
<!DOCTYPE html>
<meta charset="utf-8">
<title>Tests Stale While Revalidate is not executed for fetch API</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script>
promise_test(async (test) => {
var request_token = token();
var client_hint_headers = [
"sec-ch-ua",
"sec-ch-ua-arch",
"sec-ch-ua-platform",
"sec-ch-ua-model",
];
const response = await fetch(`echo_ua_client_hints_received.py`);
client_hint_headers.forEach(header => {
if(response.headers.get(header+"-recieved")) {
assert_equals(response.headers.get(header+"-recieved").slice(0,1), "\"");
assert_equals(response.headers.get(header+"-recieved").slice(-1), "\"");
}
});
}, 'User agent client hint header values are surrounded by quotes');
</script>
\ No newline at end of file
Accept-CH: ua,arch,platform,model
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment