Skip to content

Commit 38e7644

Browse files
committed
Add how to construct a network.Request
1 parent ae1d578 commit 38e7644

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
@@ -2737,7 +2737,6 @@ The <dfn export for=commands>browsingContext.captureScreenshot</dfn> command
27372737
captures an image of the given browsing context, and returns it as a
27382738
Base64-encoded string.
27392739

2740-
27412740
<dl>
27422741
<dt>Command Type</dt>
27432742
<dd>
@@ -3687,7 +3686,7 @@ NetworkCookie = {
36873686
};
36883687
</pre>
36893688

3690-
The <code>NetworkCookie</code> type represents a cookie.
3689+
The <code>Cookie</code> type represents a cookie.
36913690

36923691
If the cookie value can be represented as a UTF-8 encoded string, the
36933692
<code>value</code> field will be present. Otherwise the <code>binaryValue</code>
@@ -3717,7 +3716,7 @@ NetworkFetchTimingInfo = {
37173716
};
37183717
</pre>
37193718

3720-
The <code>NetworkFetchTimingInfo</code> type represents the time of each part of
3719+
The <code>FetchTimingInfo</code> type represents the time of each part of
37213720
the request, relative to <code>requestTime</code>.
37223721

37233722
TODO: Add service worker fields
@@ -3734,13 +3733,41 @@ NetworkHeader = {
37343733
};
37353734
</pre>
37363735

3737-
The <code>NetworkHeader</code> type represents a single request header.
3736+
The <code>Header</code> type represents a single request header.
37383737

37393738
If the header value can be represented as a UTF-8 encoded string, the
37403739
<code>value</code> field will be present. Otherwise the <code>binaryValue</code>
37413740
field will be present and consist of an array of integers representing the bytes
37423741
of the header.
37433742

3743+
<div algorithm>
3744+
3745+
To <dfn>get a Header</dfn> given |name bytes| and |value bytes|:
3746+
3747+
1. Let |name| be the result of [=UTF-8 decode=] with |name bytes|.
3748+
3749+
Assert: Since header names are constrained to be ASCII-only this cannot fail.
3750+
3751+
1. Let |utf8 decoded value| be the result of [=UTF-8 decode without BOM or fail=]
3752+
with |value byes|.
3753+
3754+
1. If |utf8 decoded value| is failure, then:
3755+
3756+
1. let |value| be null and |binary value| be a list.
3757+
3758+
1. For each |byte| in |value bytes|:
3759+
3760+
1. Append the [=value=] of |byte| to |binary value|.
3761+
3762+
Otherwise: let |value| be |utf8 decoded value| and let |binary value|
3763+
be null.
3764+
3765+
1. Return a map matching the <code>NetworkHeader</code> production, with the
3766+
<code>name</code> field set to |string name|, the <code>value</code> field
3767+
set to |value| if it's not null, or omitted otherwise, and the
3768+
<code>binaryValue</code> field set to |binary value| if it's not null, or
3769+
omitted otherwise.
3770+
37443771
#### The network.Initiator type #### {#type-network-Initiator}
37453772

37463773
[=Remote end definition=] and [=local end definition=]
@@ -3755,7 +3782,7 @@ NetworkInitiator = {
37553782
};
37563783
</pre>
37573784

3758-
The <code>NetworkInitiatior</code> type represents the source of a network request.
3785+
The <code>Initiatior</code> type represents the source of a network request.
37593786

37603787
TODO: Align more closely with Fetch here?
37613788

@@ -3780,15 +3807,62 @@ NetworkRequestData = {
37803807
method: text,
37813808
headers: [ *NetworkHeader ],
37823809
cookies: [ *NetworkCookie ],
3783-
?body: text,
37843810
headersSize: uint,
37853811
bodySize: uint,
37863812
};
37873813
</pre>
37883814

37893815
The <code>RequestData</code> type represents an ongoing network request.
37903816

3791-
TODO: Body is actually bytes, not clear how to handle it as text
3817+
<div algorithm>
3818+
3819+
To <dfn>get the request data</div> given |request|:
3820+
3821+
1. Let |url| be the result of running the [=URL serializer=] with |request|'s
3822+
[=URL=].
3823+
3824+
1. Let |method| be |request|'s [=method=].
3825+
3826+
1. let |body size| be 0.
3827+
3828+
1. Let |body| be request's [=body=].
3829+
3830+
1. If |body| is a [=byte sequence=], let |body size| be the length of that
3831+
sequence. Otherwise if |body| is a [=body=] then let |body size| be that
3832+
body's [=length=] if it's not null, or 0 otherwise.
3833+
3834+
TODO: Should we handle the case where the body length is not yet known?
3835+
3836+
1. Let |headers size| be the size in bytes of |request|'s [=headers list=] when
3837+
serialized as mandated by [=HTTP=].
3838+
3839+
Note: for protocols which allow header compression, this is the compressed
3840+
size of the headers, as sent over the network.
3841+
3842+
1. Let |headers| be an empty list.
3843+
3844+
1. Let |cookies| be an empty list.
3845+
3846+
1. For each (|name|, |value|) in |request|'s [=headers list=]:
3847+
3848+
1. Append the result of [=get a Header=] with |name| and |value| to |headers|.
3849+
3850+
1. If |name| is a [=byte-case-insensitive=] match for "<code>Cookie</code>" then:
3851+
3852+
1. TODO: Add cookies
3853+
3854+
CDP puts all cookies in the cookie store for the destination URL into the
3855+
request object, and then marks the ones that were not actual sent with the
3856+
request with the reason they were blocked.
3857+
3858+
It's not clear if we want to do the same, or just include the cookies that
3859+
were actually sent.
3860+
3861+
1. Return a map matching the <code>NetworkRequestData</code>
3862+
production, with the <code>url</code> field set to |url|, the
3863+
<code>method</code> field set to |method|, the <code>headers</code> field set
3864+
to |headers|, the <code>headersSize</code> field set to |headers size| and
3865+
the <code>bodySize</code> field set to |body size|.
37923866
37933867
#### The network.ResponseContent type #### {#type-network-ResponseContent}
37943868
@@ -3853,6 +3927,10 @@ The <code>RequestData</code> type represents the response to a netowrk request.
38533927
</dd>
38543928
</dl>
38553929
3930+
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi before
3931+
request send</dfn> steps given |request|:
3932+
3933+
38563934
#### The network.fetchError Event #### {#event-network-fetchError}
38573935

38583936
<dl>
@@ -3921,6 +3999,12 @@ After the full response body is received.
39213999

39224000
After the response headers are received but before the body.
39234001

4002+
The [=remote end event trigger=] is the <dfn export>WebDriver BiDi before
4003+
response started</dfn> steps given |request| and |response|:
4004+
4005+
1. Let |request data| be the result of [=get the request data=] given |request|.
4006+
4007+
39244008
## The script Module ## {#module-script}
39254009

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

0 commit comments

Comments
 (0)