-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RemoteContextHelper: expose all request headers
Previously, we would manually update executor.sub.html to output request headers into the HTML body. The result would be stored as a global variable, window.requestHeaders, with absent headers having the string value "absent". This improves the situation in several ways: * Adds a first-class API, getRequestHeaders(), to RemoteContextHelper, instead of relying on the implicit knowledge that if you use executeScript(), you can retrieve a global window.requestHeaders. * The returned object is a Headers object, instead of an object literal. Absent headers are simply not in the object, instead of being the string "absent". * The returned object has all request headers, not a manually-curated list. * Because all headers are sent across the boundary at once, in the single getRequestHeaders() call, we no longer have to call into the remote context using executeScript() once per header of interest. Bug: 1456579 Change-Id: I2c88fde4ed3007e712496f6ab807851e89ac6c6f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4778110 Reviewed-by: Fergal Daly <fergal@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#1185025}
- Loading branch information
Showing
5 changed files
with
68 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...pt/html/browsers/browsing-the-web/remote-context-helper-tests/getRequestHeaders.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// META: title=RemoteContextHelper with defaults | ||
// META: script=/common/dispatcher/dispatcher.js | ||
// META: script=/common/get-host-info.sub.js | ||
// META: script=/common/utils.js | ||
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js | ||
// META: script=./resources/test-helper.js | ||
|
||
'use strict'; | ||
|
||
promise_test(async t => { | ||
const rcHelper = new RemoteContextHelper(); | ||
const main = await rcHelper.addWindow(); | ||
|
||
const headers = await main.getRequestHeaders(); | ||
|
||
assert_equals(headers.constructor, Headers); | ||
assert_true(headers.has("user-agent"), "user-agent is present"); | ||
}); |
23 changes: 23 additions & 0 deletions
23
...nal/wpt/html/browsers/browsing-the-web/remote-context-helper/resources/executor-window.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import json | ||
|
||
def main(request, response): | ||
initRequestHeaders = "" | ||
for header_name in request.headers.keys(): | ||
for header_value in request.headers.get_list(header_name): | ||
js_name = json.dumps(header_name.lower().decode("utf-8")) | ||
js_value = json.dumps(header_value.decode("utf-8")) | ||
initRequestHeaders += f"window.__requestHeaders.append({js_name}, {js_value});\n" | ||
|
||
return (200, [("Content-Type", "text/html")], f""" | ||
<!DOCTYPE HTML> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="./executor-common.js"></script> | ||
<script src="./executor-window.js"></script> | ||
<body> | ||
<script> | ||
window.__requestHeaders = new Headers(); | ||
{initRequestHeaders} | ||
requestExecutor(); | ||
</script> | ||
""") |
16 changes: 0 additions & 16 deletions
16
...rnal/wpt/html/browsers/browsing-the-web/remote-context-helper/resources/executor.sub.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters