diff --git a/fetch/compression-dictionary/dictionary-fetch-with-link-element.tentative.https.html b/fetch/compression-dictionary/dictionary-fetch-with-link-element.tentative.https.html index 3741390548abea..c17dc55906eb26 100644 --- a/fetch/compression-dictionary/dictionary-fetch-with-link-element.tentative.https.html +++ b/fetch/compression-dictionary/dictionary-fetch-with-link-element.tentative.https.html @@ -49,7 +49,7 @@ getRemoteHostUrl(`${kRegisterDictionaryPath}?save_header=${dict_token}`); addLinkRelCompressionDictionaryElement(url, 'anonymous'); const headers = await waitUntilPreviousRequestHeaders( - t, dict_token, /*check_remote=*/ true); + t, dict_token, {check_remote: true}); assert_true(headers !== undefined, 'Headers should be available'); assert_equals(headers['sec-fetch-mode'], 'cors'); diff --git a/fetch/compression-dictionary/dictionary-fetch-with-link-header-in-early-hints.tentative.https.h2.html b/fetch/compression-dictionary/dictionary-fetch-with-link-header-in-early-hints.tentative.https.h2.html new file mode 100644 index 00000000000000..dfc6222a60328d --- /dev/null +++ b/fetch/compression-dictionary/dictionary-fetch-with-link-header-in-early-hints.tentative.https.h2.html @@ -0,0 +1,9 @@ + + + + diff --git a/fetch/compression-dictionary/resources/compression-dictionary-util.sub.js b/fetch/compression-dictionary/resources/compression-dictionary-util.sub.js index d86f534fbd040d..bd63c8b60709ad 100644 --- a/fetch/compression-dictionary/resources/compression-dictionary-util.sub.js +++ b/fetch/compression-dictionary/resources/compression-dictionary-util.sub.js @@ -96,8 +96,9 @@ async function waitUntilAvailableDictionaryHeader(test, { // Checks the HTTP request headers which was sent to the server with `token` // to register a dictionary. -async function checkPreviousRequestHeaders(token, check_remote = false) { - let url = `./resources/register-dictionary.py?get_previous_header=${token}`; +async function checkPreviousRequestHeaders(token, options = {}) { + const { check_remote = false, use_http2 = false } = options; + let url = `${use_http2 ? kRegisterDictionaryHttp2Path : kRegisterDictionaryPath}?get_previous_header=${token}`; if (check_remote) { url = getRemoteHostUrl(url); } @@ -108,12 +109,12 @@ async function checkPreviousRequestHeaders(token, check_remote = false) { // `token` to register a dictionary is available, and returns the header. If the // header is not available after the specified number of retries, returns // `undefined`. -async function waitUntilPreviousRequestHeaders( - test, token, check_remote = false) { +async function waitUntilPreviousRequestHeaders(test, token, options = {}) { + const { check_remote = false, use_http2 = false } = options; for (let retry_count = 0; retry_count <= kCheckPreviousRequestHeadersMaxRetry; retry_count++) { const header = - (await checkPreviousRequestHeaders(token, check_remote))['headers']; + (await checkPreviousRequestHeaders(token, {check_remote, use_http2}))['headers']; if (header) { return header; } @@ -156,3 +157,11 @@ async function registerAltDictionaryAndWait(t) { await waitUntilAvailableDictionaryHeader(t, {use_alt_path: true}), kDefaultDictionaryHashBase64); } + +function navigateToTestWithCompressionDictionaryEarlyHints(test_url, dictionary_url) { + const params = new URLSearchParams(); + params.set("test_url", test_url); + params.set("dictionary_url", dictionary_url); + const url = `${RESOURCES_PATH}/early-hint-for-compression-dictionary-test-loader.h2.py?${params.toString()}`; + window.location.replace(new URL(url, window.location)); +} diff --git a/fetch/compression-dictionary/resources/dictionary-fetch-with-link-header-in-early-hints.tentative.https.h2.html b/fetch/compression-dictionary/resources/dictionary-fetch-with-link-header-in-early-hints.tentative.https.h2.html new file mode 100644 index 00000000000000..5265d3993352c1 --- /dev/null +++ b/fetch/compression-dictionary/resources/dictionary-fetch-with-link-header-in-early-hints.tentative.https.h2.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/fetch/compression-dictionary/resources/early-hint-for-compression-dictionary-test-loader.h2.py b/fetch/compression-dictionary/resources/early-hint-for-compression-dictionary-test-loader.h2.py new file mode 100644 index 00000000000000..d2efb64b3e83f1 --- /dev/null +++ b/fetch/compression-dictionary/resources/early-hint-for-compression-dictionary-test-loader.h2.py @@ -0,0 +1,32 @@ +import os +import time + +def _remove_relative_resources_prefix(path): + if path.startswith("resources/"): + return path[len("resources/"):] + return path + +def handle_headers(frame, request, response): + # Send a 103 response. + dictionary_url = request.GET.first(b"dictionary_url").decode() + link_header_value = "<{}>; rel=\"compression-dictionary\"".format(dictionary_url).encode() + early_hints = [ + (b":status", b"103"), + (b"link", link_header_value), + ] + response.writer.write_raw_header_frame(headers=early_hints, + end_headers=True) + + # Delay before sending the 200 response. + time.sleep(0.2) + response.status = 200 + response.headers[b"content-type"] = "text/html" + response.write_status_headers() + +def main(request, response): + test_path = _remove_relative_resources_prefix( + request.GET[b"test_url"].decode("utf-8")) + current_dir = os.path.dirname(os.path.realpath(__file__)) + file_path = os.path.join(current_dir, test_path) + test_content = open(file_path, "r").read() + response.writer.write_data(item=test_content, last=True)