diff --git a/signed-exchange/resources/generate-test-sxgs.sh b/signed-exchange/resources/generate-test-sxgs.sh index 81a5e043469c55..7214fc148c3648 100755 --- a/signed-exchange/resources/generate-test-sxgs.sh +++ b/signed-exchange/resources/generate-test-sxgs.sh @@ -576,4 +576,22 @@ gen-signedexchange \ -miRecordSize 100 \ -responseHeader "link:<$inner_url_origin/signed-exchange/resources/sxg-subresource-script.js>;rel=allowed-alt-sxg;header-integrity=\"$header_integrity\",<$inner_url_origin/signed-exchange/resources/sxg-subresource-script.js>;rel=preload;as=script" + +# A Signed Exchange for testing prefetch. +# The id query value "XXX..." of prefetch-test-cert.py will be replaced with +# UUID for stash token by prefetch-test-sxg.py. +gen-signedexchange \ + -version $sxg_version \ + -uri $inner_url_origin/signed-exchange/resources/inner-url.html \ + -status 200 \ + -content sxg-prefetch-test.html \ + -certificate $certfile \ + -certUrl $wpt_test_remote_origin/signed-exchange/resources/prefetch-test-cert.py?id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \ + -validityUrl $inner_url_origin/signed-exchange/resources/resource.validity.msg \ + -privateKey $keyfile \ + -date 2020-01-29T00:00:00Z \ + -expire 168h \ + -o sxg/sxg-prefetch-test.sxg \ + -miRecordSize 100 + rm -fr $tmpdir diff --git a/signed-exchange/resources/prefetch-test-cert.py b/signed-exchange/resources/prefetch-test-cert.py new file mode 100644 index 00000000000000..7aec0aace55108 --- /dev/null +++ b/signed-exchange/resources/prefetch-test-cert.py @@ -0,0 +1,17 @@ +import os + + +def main(request, response): + stash_id = request.GET.first("id") + if request.server.stash.take(stash_id) is not None: + response.status = (404, "Not Found") + response.headers.set("Content-Type", "text/plain") + return "not found" + request.server.stash.put(stash_id, True) + + path = os.path.join(os.path.dirname(__file__), "127.0.0.1.sxg.pem.cbor") + body = open(path, "rb").read() + + response.headers.set("Content-Type", "application/cert-chain+cbor") + response.headers.set("Cache-Control", "public, max-age=600") + return body diff --git a/signed-exchange/resources/prefetch-test-sxg.py b/signed-exchange/resources/prefetch-test-sxg.py new file mode 100644 index 00000000000000..822273ec6919ff --- /dev/null +++ b/signed-exchange/resources/prefetch-test-sxg.py @@ -0,0 +1,19 @@ +import os + + +def main(request, response): + stash_id = request.GET.first("id") + if request.server.stash.take(stash_id) is not None: + response.status = (404, "Not Found") + response.headers.set("Content-Type", "text/plain") + return "not found" + request.server.stash.put(stash_id, True) + + path = os.path.join(os.path.dirname(__file__), "sxg", "sxg-prefetch-test.sxg") + body = open(path, "rb").read() + + response.headers.set("Content-Type", "application/signed-exchange;v=b3") + response.headers.set("X-Content-Type-Options", "nosniff") + response.headers.set("Cache-Control", "public, max-age=600") + + return body.replace('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', stash_id) diff --git a/signed-exchange/resources/sxg-prefetch-test.html b/signed-exchange/resources/sxg-prefetch-test.html new file mode 100644 index 00000000000000..5383a4a56100c9 --- /dev/null +++ b/signed-exchange/resources/sxg-prefetch-test.html @@ -0,0 +1,5 @@ + +