Skip to content

Commit

Permalink
Fetch: Track protocol information in Response.
Browse files Browse the repository at this point in the history
This CL plumbs three protocol related fields through the fetch API
Response internal representation:

1) The |alpn_negotiated_protocol| which is set for TLS negotiated
protocols like H2.
2) The |connection_info| enumeration which includes information on
older protocols like H1.
3) The |was_fetched_via_spdy| boolean which is set for H2.

The first two values, |alpn_negotiated_protocol| and |connection_info|,
are collectively used to populate the
`PerformanceResourceTiming.nextHopProtocol` value.  They are also both
used to populate the correct protocol information in the devtools network
panel.

The |was_fetched_via_spdy| boolean is used to the deprecated
`navigator.chrome.loadTimes().wasFetchedViaSpdy` property.

Without this plumbing the resulting exposed values will generally be
wrong if the page loaded via a service worker with a FetchEvent handler.
For example, `PerformanceResourceTiming.nextHopeProtocol` is always the
empty string for resources loaded via a service worker that does a
pass-through or cached load.

This CL also plumbs these values through the cache_storage layer.  While
that may seem unintuitive at first, since the data is coming from disk,
it matches the behavior when loading from http cache.  Generally the
values represent the protocol used to originally load the response and
are persisted in the cache.

I believe this also matches the cache_storage spec where Response
objects are effectively held in an array without any serialization
or deserialization where data would be lost:

https://w3c.github.io/ServiceWorker/#cache-objects

Although the spec is not currently clear if the protocol information
lives on the response object, its not clear where else it could be
stored.  This should become clearer once the Resource Timing spec is
integrated with the fetch spec in:

w3c/resource-timing#39

This CL includes an automated WPT test for the
`PerformanceResourceTiming.nextHopProtocol` value since we can verify
that its populated with "http/1.1" instead of the empty string.
Unfortunately it was not possible to writes for the other attributes
since we do not currently have the ability to test against an http2
server.  Both `wasFetchedViaSpdy` and the devtools output effectively
need an http2 server to observe differences.  These parts of the CL were
manually tested.

Bug: 1069813
Change-Id: I84819ef5a53e9246f9e383e56b6d7e5901a7a243
  • Loading branch information
wanderview authored and chromium-wpt-export-bot committed May 18, 2020
1 parent adae164 commit 7a674cc
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions service-workers/service-worker/next-hop-protocol.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Service Worker: Verify nextHopProtocol is set correctly</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>

async function getNextHopProtocol(frame, url_suffix) {
let url = new URL(`resources/empty.js${url_suffix}`, self.location).href;
await frame.contentWindow.fetch(url).then(r => r.text());
let entryList = frame.contentWindow.performance.getEntriesByName(url);
let entry = entryList[entryList.length - 1];
return entry.nextHopProtocol;
}

promise_test(async (t) => {
const scope = 'resources/empty.html?next-hop-protocol';
const script = 'resources/fetch-rewrite-worker.js';
const expected_h1_protocol = 'http/1.1';
let frame;

const registration =
await service_worker_unregister_and_register(t, script, scope);
t.add_cleanup(async _ => registration.unregister());
await wait_for_state(t, registration.installing, 'activated');
frame = await with_iframe(scope);
t.add_cleanup(_ => frame.remove());

assert_equals(await getNextHopProtocol(frame, '?generate-png'), '',
'nextHopProtocol is not set on synthetic response');
assert_equals(await getNextHopProtocol(frame, '?ignore'), 'http/1.1',
'nextHopProtocol is set on fallback');
assert_equals(await getNextHopProtocol(frame, ''), 'http/1.1',
'nextHopProtocol is set on pass-through');
assert_equals(await getNextHopProtocol(frame, '?cache'), 'http/1.1',
'nextHopProtocol is set on cached response');
}, 'nextHopProtocol is reported correctly when routed via a service worker.');

</script>

0 comments on commit 7a674cc

Please sign in to comment.