Skip to content

Commit 3ab5102

Browse files
authored
Editorial: consistently use a body + type tuple
Previously multiple functions returned ad-hoc tuples of body + mime type. This commit consolidates all of these into a concrete "body with type" tuple. Downstream: whatwg/xhr#349. Closes #1410.
1 parent 3ae445e commit 3ab5102

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

fetch.bs

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,12 @@ null), run these steps. <var>processBody</var> must be an algorithm accepting a
12971297

12981298
<hr>
12991299

1300+
<p>A <dfn export>body with type</dfn> is a <a for=/>tuple</a> that consists of a
1301+
<dfn export for="body with type">body</dfn> (a <a for=/>body</a>) and a
1302+
<dfn export for="body with type">type</dfn> (a <a for=/>header value</a> or null).
1303+
1304+
<hr>
1305+
13001306
<p>To <dfn export>handle content codings</dfn> given <var>codings</var> and <var>bytes</var>, run
13011307
these steps:
13021308

@@ -3881,8 +3887,8 @@ the request.
38813887
<var>crossOriginIsolatedCapability</var>.
38823888

38833889
<li><p>If <var>request</var>'s <a for=request>body</a> is a <a for=/>byte sequence</a>, then set
3884-
<var>request</var>'s <a for=request>body</a> to the first return value of
3885-
<a for=BodyInit>safely extracting</a> <var>request</var>'s <a for=request>body</a>.
3890+
<var>request</var>'s <a for=request>body</a> to the <a for="body with type">body</a> of the result
3891+
of <a for=BodyInit>safely extracting</a> <var>request</var>'s <a for=request>body</a>.
38863892

38873893
<li><p>If <var>request</var>'s <a for=request>window</a> is "<code>client</code>", then set
38883894
<var>request</var>'s <a for=request>window</a> to <var>request</var>'s <a for=request>client</a>,
@@ -4308,8 +4314,9 @@ steps:
43084314
<var>request</var>'s <a for=request>integrity metadata</a>, then run
43094315
<var>processBodyError</var> and abort these steps. [[!SRI]]
43104316

4311-
<li><p>Set <var>response</var>'s <a for=response>body</a> to the first return value of
4312-
<a for=BodyInit>safely extracting</a> <var>bytes</var>.
4317+
<li><p>Set <var>response</var>'s <a for=response>body</a> to the
4318+
<a for="body with type">body</a> of the result of <a for=BodyInit>safely extracting</a>
4319+
<var>bytes</var>.
43134320

43144321
<li><p>Run <a>fetch response handover</a> given <var>fetchParams</var> and <var>response</var>.
43154322
</ol>
@@ -4850,8 +4857,9 @@ run these steps:
48504857

48514858
<li>
48524859
<p>If <var>request</var>'s <a for=request>body</a> is non-null, then set <var>request</var>'s
4853-
<a for=request>body</a> to the first return value of <a for=BodyInit>safely extracting</a>
4854-
<var>request</var>'s <a for=request>body</a>'s <a for=body>source</a>.
4860+
<a for=request>body</a> to the <a for="body with type">body</a> of the result of
4861+
<a for=BodyInit>safely extracting</a> <var>request</var>'s <a for=request>body</a>'s
4862+
<a for=body>source</a>.
48554863

48564864
<p class="note no-backref"><var>request</var>'s <a for=request>body</a>'s <a for=body>source</a>'s
48574865
nullity has already been checked.
@@ -5351,9 +5359,9 @@ steps. They return a <a for=/>response</a>.
53515359
<li><p>If <var>request</var>'s <a for=request>body</a>'s <a for=body>source</a> is null,
53525360
then return a <a>network error</a>.
53535361

5354-
<li><p>Set <var>request</var>'s <a for=request>body</a> to the first return value of
5355-
<a for=BodyInit>safely extracting</a> <var>request</var>'s <a for=request>body</a>'s
5356-
<a for=body>source</a>.
5362+
<li><p>Set <var>request</var>'s <a for=request>body</a> to the <a for="body with type">body</a>
5363+
of the result of <a for=BodyInit>safely extracting</a> <var>request</var>'s
5364+
<a for=request>body</a>'s <a for=body>source</a>.
53575365
</ol>
53585366

53595367
<li>
@@ -6451,9 +6459,8 @@ typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) XMLHt
64516459

64526460
typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit;</pre>
64536461

6454-
<p>To <dfn for=BodyInit export>safely extract</dfn> a <a for=/>body</a> and a
6455-
`<code>Content-Type</code>` <a for=/>header value</a> from a <a for=/>byte sequence</a> or
6456-
{{BodyInit}} object <var>object</var>, run these steps:
6462+
<p>To <dfn for=BodyInit export>safely extract</dfn> a <a for=/>body with type</a> from a
6463+
<a for=/>byte sequence</a> or {{BodyInit}} object <var>object</var>, run these steps:
64576464

64586465
<ol>
64596466
<li>
@@ -6464,15 +6471,15 @@ typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit;</pre>
64646471
<a for=ReadableStream>locked</a>.
64656472
</ol>
64666473

6467-
<li><p>Return the results of <a for=BodyInit>extracting</a> <var>object</var>.
6474+
<li><p>Return the result of <a for=BodyInit>extracting</a> <var>object</var>.
64686475
</ol>
64696476

64706477
<p class="note no-backref">The <a for=BodyInit>safely extract</a> operation is a subset of the
64716478
<a for=BodyInit>extract</a> operation that is guaranteed to not throw an exception.
64726479

6473-
<p>To <dfn id=concept-bodyinit-extract for=BodyInit export>extract</dfn> a <a for=/>body</a> and a
6474-
`<code>Content-Type</code>` <a for=/>header value</a> from a <a for=/>byte sequence</a> or
6475-
{{BodyInit}} object <var>object</var>, with an optional boolean
6480+
<p>To <dfn id=concept-bodyinit-extract for=BodyInit export>extract</dfn> a
6481+
<a for=/>body with type</a> from a <a for=/>byte sequence</a> or {{BodyInit}} object
6482+
<var>object</var>, with an optional boolean
64766483
<dfn id=keepalive for=BodyInit/extract export><var>keepalive</var></dfn> (default false), run these
64776484
steps:
64786485

@@ -6487,7 +6494,7 @@ steps:
64876494

64886495
<li><p>Let <var>length</var> be null.
64896496

6490-
<li><p>Let <var>Content-Type</var> be null.
6497+
<li><p>Let <var>type</var> be null.
64916498

64926499
<li>
64936500
<p>Switch on <var>object</var>:
@@ -6502,7 +6509,7 @@ steps:
65026509
<p>Set <var>length</var> to <var>object</var>'s {{Blob/size}}.
65036510

65046511
<p>If <var>object</var>'s {{Blob/type}}
6505-
attribute is not the empty byte sequence, set <var>Content-Type</var> to its value.
6512+
attribute is not the empty byte sequence, set <var>type</var> to its value.
65066513
<!-- Blob reading is not defined and blobs don't have an internal data model to poke at -->
65076514

65086515
<dt><a for=/>byte sequence</a>
@@ -6523,7 +6530,7 @@ steps:
65236530
<p>Set <var>length</var> to <span class=XXX>unclear, see
65246531
<a href="https://github.com/whatwg/html/issues/6424">html/6424</a> for improving this</span>.
65256532

6526-
<p>Set <var>Content-Type</var> to `<code>multipart/form-data; boundary=</code>`, followed by the
6533+
<p>Set <var>type</var> to `<code>multipart/form-data; boundary=</code>`, followed by the
65276534
<a><code>multipart/form-data</code> boundary string</a> generated by the
65286535
<a><code>multipart/form-data</code> encoding algorithm</a>.
65296536

@@ -6533,14 +6540,14 @@ steps:
65336540
<a lt="urlencoded serializer"><code>application/x-www-form-urlencoded</code> serializer</a> with
65346541
<var>object</var>'s <a for=URLSearchParams>list</a>.
65356542

6536-
<p>Set <var>Content-Type</var> to
6543+
<p>Set <var>type</var> to
65376544
`<code>application/x-www-form-urlencoded;charset=UTF-8</code>`.
65386545

65396546
<dt><a for=/>scalar value string</a>
65406547
<dd>
65416548
<p>Set <var>source</var> to the <a>UTF-8 encoding</a> of <var>object</var>.
65426549

6543-
<p>Set <var>Content-Type</var> to `<code>text/plain;charset=UTF-8</code>`.
6550+
<p>Set <var>type</var> to `<code>text/plain;charset=UTF-8</code>`.
65446551

65456552
<dt>{{ReadableStream}}
65466553
<dd>
@@ -6572,7 +6579,7 @@ steps:
65726579
<var>stream</var>, <a for=body>source</a> is <var>source</var>, and <a for=body>length</a> is
65736580
<var>length</var>.
65746581

6575-
<li><p>Return <var>body</var> and <var>Content-Type</var>.
6582+
<li><p>Return (<var>body</var>, <var>type</var>).
65766583
</ol>
65776584

65786585

@@ -7303,17 +7310,18 @@ constructor steps are:
73037310
<p>If <var>init</var>["{{RequestInit/body}}"] <a for=map>exists</a> and is non-null, then:
73047311

73057312
<ol>
7306-
<li><p>Let <var>Content-Type</var> be null.
7313+
<li><p>Let <var>bodyWithType</var> be the result of <a for=BodyInit>extracting</a>
7314+
<var>init</var>["{{RequestInit/body}}"], with <a for=BodyInit/extract><var>keepalive</var></a>
7315+
set to <var>request</var>'s <a for=request>keepalive</a>.
73077316

7308-
<li><p>Set <var>initBody</var> and <var>Content-Type</var> to the result of
7309-
<a for=BodyInit>extracting</a> <var>init</var>["{{RequestInit/body}}"], with
7310-
<a for=BodyInit/extract><var>keepalive</var></a> set to <var>request</var>'s
7311-
<a for=request>keepalive</a>.
7317+
<li><p>Set <var>initBody</var> to <var>bodyWithType</var>'s <a for="body with type">body</a>.
73127318

7313-
<li><p>If <var>Content-Type</var> is non-null and <a>this</a>'s <a for=Request>headers</a>'s
7319+
<li><p>Let <var>type</var> be <var>bodyWithType</var>'s <a for="body with type">type</a>.
7320+
7321+
<li><p>If <var>type</var> is non-null and <a>this</a>'s <a for=Request>headers</a>'s
73147322
<a for=Headers>header list</a> <a for="header list">does not contain</a>
73157323
`<code>Content-Type</code>`, then <a for=Headers>append</a> (`<code>Content-Type</code>`,
7316-
<var>Content-Type</var>) to <a>this</a>'s <a for=Request>headers</a>.
7324+
<var>type</var>) to <a>this</a>'s <a for=Request>headers</a>.
73177325
</ol>
73187326

73197327
<li><p>Let <var>inputOrInitBody</var> be <var>initBody</var> if it is non-null; otherwise
@@ -7572,15 +7580,18 @@ constructor steps are:
75727580
<p class="note no-backref">101 is included in <a>null body status</a> due to its use elsewhere.
75737581
It does not affect this step.
75747582

7575-
<li><p>Let <var>Content-Type</var> be null.
7583+
<li><p>Let <var>bodyWithType</var> be the result of <a for=BodyInit>extracting</a>
7584+
<var>body</var>.
7585+
7586+
<li><p>Set <a>this</a>'s <a for=Response>response</a>'s <a for=response>body</a> to
7587+
<var>bodyWithType</var>'s <a for="body with type">body</a>.
75767588

7577-
<li><p>Set <a>this</a>'s <a for=Response>response</a>'s <a for=response>body</a> and
7578-
<var>Content-Type</var> to the result of <a for=BodyInit>extracting</a> <var>body</var>.
7589+
<li><p>Let <var>type</var> be <var>bodyWithType</var>'s <a for="body with type">type</a>.
75797590

7580-
<li><p>If <var>Content-Type</var> is non-null and <a>this</a>'s <a for=Response>response</a>'s
7591+
<li><p>If <var>type</var> is non-null and <a>this</a>'s <a for=Response>response</a>'s
75817592
<a for=response>header list</a> <a for="header list">does not contain</a>
75827593
`<code>Content-Type</code>`, then <a for="header list">append</a> (`<code>Content-Type</code>`,
7583-
<var>Content-Type</var>) to <a>this</a>'s <a for=Response>response</a>'s
7594+
<var>type</var>) to <a>this</a>'s <a for=Response>response</a>'s
75847595
<a for=response>header list</a>.
75857596
</ol>
75867597
</ol>

0 commit comments

Comments
 (0)