Skip to content

Commit 1f4f511

Browse files
committed
Add how to construct a network.Request
1 parent e493c9a commit 1f4f511

File tree

1 file changed

+91
-7
lines changed

1 file changed

+91
-7
lines changed

index.bs

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,6 @@ The <dfn export for=commands>browsingContext.captureScreenshot</dfn> command
27772777
captures an image of the given browsing context, and returns it as a
27782778
Base64-encoded string.
27792779

2780-
27812780
<dl>
27822781
<dt>Command Type</dt>
27832782
<dd>
@@ -3756,7 +3755,7 @@ NetworkCookie = {
37563755
};
37573756
</pre>
37583757

3759-
The <code>NetworkCookie</code> type represents a cookie.
3758+
The <code>Cookie</code> type represents a cookie.
37603759

37613760
If the cookie value can be represented as a UTF-8 encoded string, the
37623761
<code>value</code> field will be present. Otherwise the <code>binaryValue</code>
@@ -3786,7 +3785,7 @@ NetworkFetchTimingInfo = {
37863785
};
37873786
</pre>
37883787

3789-
The <code>NetworkFetchTimingInfo</code> type represents the time of each part of
3788+
The <code>FetchTimingInfo</code> type represents the time of each part of
37903789
the request, relative to <code>requestTime</code>.
37913790

37923791
TODO: Add service worker fields
@@ -3803,13 +3802,41 @@ NetworkHeader = {
38033802
};
38043803
</pre>
38053804

3806-
The <code>NetworkHeader</code> type represents a single request header.
3805+
The <code>Header</code> type represents a single request header.
38073806

38083807
If the header value can be represented as a UTF-8 encoded string, the
38093808
<code>value</code> field will be present. Otherwise the <code>binaryValue</code>
38103809
field will be present and consist of an array of integers representing the bytes
38113810
of the header.
38123811

3812+
<div algorithm>
3813+
3814+
To <dfn>get a Header</dfn> given |name bytes| and |value bytes|:
3815+
3816+
1. Let |name| be the result of [=UTF-8 decode=] with |name bytes|.
3817+
3818+
Assert: Since header names are constrained to be ASCII-only this cannot fail.
3819+
3820+
1. Let |utf8 decoded value| be the result of [=UTF-8 decode without BOM or fail=]
3821+
with |value byes|.
3822+
3823+
1. If |utf8 decoded value| is failure, then:
3824+
3825+
1. let |value| be null and |binary value| be a list.
3826+
3827+
1. For each |byte| in |value bytes|:
3828+
3829+
1. Append the [=value=] of |byte| to |binary value|.
3830+
3831+
Otherwise: let |value| be |utf8 decoded value| and let |binary value|
3832+
be null.
3833+
3834+
1. Return a map matching the <code>NetworkHeader</code> production, with the
3835+
<code>name</code> field set to |string name|, the <code>value</code> field
3836+
set to |value| if it's not null, or omitted otherwise, and the
3837+
<code>binaryValue</code> field set to |binary value| if it's not null, or
3838+
omitted otherwise.
3839+
38133840
#### The network.Initiator type #### {#type-network-Initiator}
38143841

38153842
[=Remote end definition=] and [=local end definition=]
@@ -3824,7 +3851,7 @@ NetworkInitiator = {
38243851
};
38253852
</pre>
38263853

3827-
The <code>NetworkInitiatior</code> type represents the source of a network request.
3854+
The <code>Initiatior</code> type represents the source of a network request.
38283855

38293856
TODO: Align more closely with Fetch here?
38303857

@@ -3849,15 +3876,62 @@ NetworkRequestData = {
38493876
method: text,
38503877
headers: [ *NetworkHeader ],
38513878
cookies: [ *NetworkCookie ],
3852-
?body: text,
38533879
headersSize: uint,
38543880
bodySize: uint,
38553881
};
38563882
</pre>
38573883

38583884
The <code>RequestData</code> type represents an ongoing network request.
38593885

3860-
TODO: Body is actually bytes, not clear how to handle it as text
3886+
<div algorithm>
3887+
3888+
To <dfn>get the request data</div> given |request|:
3889+
3890+
1. Let |url| be the result of running the [=URL serializer=] with |request|'s
3891+
[=URL=].
3892+
3893+
1. Let |method| be |request|'s [=method=].
3894+
3895+
1. let |body size| be 0.
3896+
3897+
1. Let |body| be request's [=body=].
3898+
3899+
1. If |body| is a [=byte sequence=], let |body size| be the length of that
3900+
sequence. Otherwise if |body| is a [=body=] then let |body size| be that
3901+
body's [=length=] if it's not null, or 0 otherwise.
3902+
3903+
TODO: Should we handle the case where the body length is not yet known?
3904+
3905+
1. Let |headers size| be the size in bytes of |request|'s [=headers list=] when
3906+
serialized as mandated by [=HTTP=].
3907+
3908+
Note: for protocols which allow header compression, this is the compressed
3909+
size of the headers, as sent over the network.
3910+
3911+
1. Let |headers| be an empty list.
3912+
3913+
1. Let |cookies| be an empty list.
3914+
3915+
1. For each (|name|, |value|) in |request|'s [=headers list=]:
3916+
3917+
1. Append the result of [=get a Header=] with |name| and |value| to |headers|.
3918+
3919+
1. If |name| is a [=byte-case-insensitive=] match for "<code>Cookie</code>" then:
3920+
3921+
1. TODO: Add cookies
3922+
3923+
CDP puts all cookies in the cookie store for the destination URL into the
3924+
request object, and then marks the ones that were not actual sent with the
3925+
request with the reason they were blocked.
3926+
3927+
It's not clear if we want to do the same, or just include the cookies that
3928+
were actually sent.
3929+
3930+
1. Return a map matching the <code>NetworkRequestData</code>
3931+
production, with the <code>url</code> field set to |url|, the
3932+
<code>method</code> field set to |method|, the <code>headers</code> field set
3933+
to |headers|, the <code>headersSize</code> field set to |headers size| and
3934+
the <code>bodySize</code> field set to |body size|.
38613935
38623936
#### The network.ResponseContent type #### {#type-network-ResponseContent}
38633937
@@ -3922,6 +3996,10 @@ The <code>RequestData</code> type represents the response to a netowrk request.
39223996
</dd>
39233997
</dl>
39243998
3999+
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi before
4000+
request send</dfn> steps given |request|:
4001+
4002+
39254003
#### The network.fetchError Event #### {#event-network-fetchError}
39264004

39274005
<dl>
@@ -3990,6 +4068,12 @@ After the full response body is received.
39904068

39914069
After the response headers are received but before the body.
39924070

4071+
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi before
4072+
response started</dfn> steps given |request| and |response|:
4073+
4074+
1. Let |request data| be the result of [=get the request data=] given |request|.
4075+
4076+
39934077
## The script Module ## {#module-script}
39944078

39954079
The <dfn export for=modules>script</dfn> module contains commands and events

0 commit comments

Comments
 (0)