Skip to content

Commit 814d903

Browse files
committed
Add network.setExtraHeaders command
This allows appending, or overriding, HTTP headers for all requests, or for all requests originating from a specific user context or a specific navigable.
1 parent a8b68a1 commit 814d903

File tree

1 file changed

+169
-19
lines changed

1 file changed

+169
-19
lines changed

index.bs

Lines changed: 169 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6204,7 +6204,8 @@ NetworkCommand = (
62046204
network.ProvideResponse //
62056205
network.RemoveDataCollector //
62066206
network.RemoveIntercept //
6207-
network.SetCacheBehavior
6207+
network.SetCacheBehavior //
6208+
network.SetExtraHeaders
62086209
)
62096210

62106211
</pre>
@@ -6238,6 +6239,15 @@ A [=remote end=] has a <dfn>navigable cache behavior map</dfn> which is a weak
62386239
map between [=/top-level traversables=] and strings representing cache
62396240
behavior. It is initially empty.
62406241

6242+
A [=BiDi session=] has a <dfn for=session>extra headers</dfn> which is a
6243+
[=struct=] with a [=struct/item=] named <dfn for="extra headers">default
6244+
headers</dfn>, which is a [=/header list=]. (initially set to an empty
6245+
[=/header list=]), a [=struct/item=] named
6246+
<dfn for="extra headers">user context headers</dfn>, which is a weak map
6247+
between [=user contexts=] and [/=header lists=],a nd a [=struct/item=] named
6248+
<dfn for="extra headers">navigable headers</dfn>, which is a weak map
6249+
between [=navigables=] and [=/header lists=].
6250+
62416251
### Network Data Collection ### {#network-data-collection}
62426252

62436253
A <dfn for="network">data</dfn> is a [=/struct=] consisting of
@@ -6587,21 +6597,8 @@ To <dfn>update the response</dfn> given |session|, |command| and |command parame
65876597

65886598
1. If |command parameters| [=map/contains=] "<code>headers</code>":
65896599

6590-
1. Let |headers| be an empty [=/header list=].
6591-
6592-
1. For |header| in |command parameters|["<code>headers</code>"]:
6593-
6594-
1. Let |deserialized header| be [=deserialize header=] with |header|.
6595-
6596-
1. If |deserialized header|'s name does not match the [=field-name token=]
6597-
production, return [=error=] with [=error code=]
6598-
"<code>invalid argument</code>".
6599-
6600-
1. If |deserialized header|'s value does not match the [=header value=]
6601-
production, return [=error=] with [=error code=]
6602-
"<code>invalid argument</code>".
6603-
6604-
1. Append |deserialized header| to |headers|.
6600+
1. Let |headers| be the result of [=trying=] to [=create a headers list=] with
6601+
|command parameters|["<code>headers</code>"].
66056602

66066603
1. Set |response|'s [=response/header list=] to |headers|.
66076604

@@ -7098,6 +7095,28 @@ To <dfn>deserialize header</dfn> given |protocol header|:
70987095

70997096
</div>
71007097

7098+
<div algoritm>
7099+
To <dfn>create a headers list</dfn> given |protocol headers|:
7100+
1. Let |headers| be an empty [=/header list=].
7101+
7102+
1. For |header| in |protocol headers|:
7103+
7104+
1. Let |deserialized header| be [=deserialize header=] with |header|.
7105+
7106+
1. If |deserialized header|'s name does not match the [=field-name token=]
7107+
production, return [=error=] with [=error code=]
7108+
"<code>invalid argument</code>".
7109+
7110+
1. If |deserialized header|'s value does not match the [=header value=]
7111+
production, return [=error=] with [=error code=]
7112+
"<code>invalid argument</code>".
7113+
7114+
1. Append |deserialized header| to |headers|.
7115+
7116+
1. Return [=success=] with data |headers|
7117+
7118+
</div>
7119+
71017120
#### The network.Initiator Type #### {#type-network-Initiator}
71027121

71037122
{^Remote end definition^} and {^local end definition^}
@@ -8778,6 +8797,134 @@ The [=remote end steps=] given <var ignore>session</var> and |command parameters
87788797

87798798
</div>
87808799

8800+
#### The network.setExtraHeaders Command #### {#command-network-setExtraHeaders}
8801+
8802+
The <dfn export for=commands>network.setExtraHeaders</dfn> command allows
8803+
specifying headers that will extend, or overwrite, existing request headers.
8804+
8805+
<dl>
8806+
<dt>Command Type</dt>
8807+
<dd>
8808+
<pre class="cddl" data-cddl-module="remote-cddl">
8809+
network.SetExtraHeaders = (
8810+
method: "network.setExtraHeaders",
8811+
params: network.SetExtraHeadersParameters
8812+
)
8813+
8814+
network.SetExtraHeadersParameters = {
8815+
headers: [+network.Header]
8816+
? contexts: [+browsingContext.BrowsingContext]
8817+
? userContexts: [+browser.UserContext]
8818+
}
8819+
</pre>
8820+
</dd>
8821+
<dt>Return Type</dt>
8822+
<dd>
8823+
<code>
8824+
EmptyResult
8825+
</code>
8826+
</dd>
8827+
</dl>
8828+
8829+
<div algorithm>
8830+
To <dfn>update headers</dfn> given |request| and |headers|:
8831+
8832+
1. Let |request headers| be |request|'s [=request/header list=].
8833+
8834+
1. For each |header| in |headers|:
8835+
8836+
1. [=header list/Set=] |header| in |request headers|.
8837+
8838+
Note: This always overwrites the existing value, if any. In particular it
8839+
doesn't append cookies to an existing `Set-Cookie` header.
8840+
8841+
</div>
8842+
8843+
<div algorithm>
8844+
To <dfn>update request headers</dfn> given |session|, |request|, and |related
8845+
navigables|:
8846+
8847+
1. Assert: |related navigables|'s [=set/size=] is 0 or 1.
8848+
8849+
Note: That means this will not work for workers associated with multiple
8850+
navigables. In that case it's unclear in which order to override the headers.
8851+
8852+
1. [=Update headers=] with |request| and |session|'s
8853+
[=session/extra headers=]' [=extra headers/default headers=]
8854+
8855+
1. Let |user context headers| be |session|'s [=session/extra headers=]'
8856+
[=extra headers/user context headers=].
8857+
8858+
1. For |navigable| in |related navigables|:
8859+
8860+
1. Let |user context| be |navigable|'s [=associated user context=].
8861+
8862+
1. If |user context headers| [=map/contains=] |user context|
8863+
then [=update headers=] with |request| and
8864+
|user context headers|[|user context|]
8865+
8866+
1. Let |navigable headers| be |session|'s [=session/extra headers=]'
8867+
[=extra headers/navigable headers=].
8868+
8869+
1. For |navigable| in |related navigables|:
8870+
8871+
1. If |navigable headers| contains |navigable| [=update headers=] with
8872+
|request| and |navigable headers|[|navigable|].
8873+
8874+
</div>
8875+
8876+
<div algorithm="remote end steps for network.setExtraHeaders">
8877+
The [=remote end steps=] given |session| and |command parameters| are:
8878+
8879+
1. If |command parameters| [=map/contains=] "<code>userContexts</code>"
8880+
and |command parameters| [=map/contains=] "<code>contexts</code>",
8881+
return [=error=] with [=error code=] [=invalid argument=].
8882+
8883+
1. Let |headers| be the result of [=trying=] to [=create a headers list=] with
8884+
|command parameters|["<code>headers</code>"].
8885+
8886+
1. If |command parameters| [=map/contains=] "<code>userContexts</code>":
8887+
8888+
1. Let |user contexts| be an empty [=/list=].
8889+
8890+
1. For |user context id| in |command parameters|["<code>userContexts</code>"]:
8891+
8892+
1. Let |user context| be [=get user context=] with |user context id|.
8893+
8894+
1. If |user context| is null, return [=error=] with [=error code=] [=invalid argument=].
8895+
8896+
1. [=list/Append=] |user context| to |user contexts|.
8897+
8898+
1. Let |target| be |session|'s [=session/extra headers=]'
8899+
[=extra headers/user context headers=]
8900+
8901+
1. For |user context| in |user contexts|:
8902+
8903+
1. Set |target|[|user context|] to |headers|.
8904+
8905+
1. Return [=success=] with data null.
8906+
8907+
1. If |command parameters| [=map/contains=] "<code>contexts</code>":
8908+
8909+
1. Let |navigables| be the result of [=trying=] to [=get valid navigables by
8910+
ids=] with |command parameters|["<code>contexts</code>"].
8911+
8912+
1. Let |target| be |session|'s [=session/extra headers=]'
8913+
[=extra headers/navigable headers=]
8914+
8915+
1. For |navigable| in |navigables|:
8916+
8917+
1. Set |target|[|navigable|] to |headers|.
8918+
8919+
1. Return [=success=] with data null.
8920+
8921+
1. Set |session|'s [=session/extra headers=]'
8922+
[=extra headers/default headers=] to |headers|.
8923+
8924+
1. Return [=success=] with data null.
8925+
8926+
</div>
8927+
87818928
### Events ### {#module-network-event}
87828929

87838930
#### The network.authRequired Event #### {#event-network-authRequired}
@@ -8906,7 +9053,7 @@ request sent</dfn> steps given |request|:
89069053
1. If the [=request originates in user context=] steps with |request| and
89079054
|user context| return true:
89089055

8909-
1. For each |session| in [=active BiDI sessions=]
9056+
1. For each |session| in [=active BiDI sessions=]:
89109057

89119058
Note: |user context| can be in not more then one
89129059
[=user context to accept insecure certificates override map=].
@@ -8962,14 +9109,17 @@ request sent</dfn> steps given |request|:
89629109

89639110
1. Let |response status| be "<code>incomplete</code>".
89649111

9112+
1. For each |session| in [=active BiDI sessions=]:
9113+
9114+
1. [=Update request headers=] with |session|, |request| and
9115+
|related navigables|.
9116+
89659117
1. For each |session| in the [=set of sessions for which an event is enabled=]
89669118
given "<code>network.beforeRequestSent</code>" and |related navigables|:
89679119

89689120
1. Let |params| be the result of [=process a network event=] with |session|,
89699121
"<code>network.beforeRequestSent</code>", and |request|.
89709122

8971-
1. If |params| is null then continue.
8972-
89739123
1. Let |initiator| be the result of [=get the initiator=] with |request|.
89749124

89759125
1. If |initiator| is not [=map/is empty|empty=], set the <code>initiator</code> field

0 commit comments

Comments
 (0)