Skip to content

Commit dab09b0

Browse files
committed
Allow User-Agent to be set, but not omitted. Also group all the header setting on a request that happens before the cache/network. Fixes #37.
1 parent 1e0918d commit dab09b0

File tree

2 files changed

+150
-122
lines changed

2 files changed

+150
-122
lines changed

Overview.html

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ <h4 id="terminology-headers"><span class="secno">3.1.2 </span>Headers</h4>
405405
<li>`<code title="">Trailer</code>`
406406
<li>`<code title="">Transfer-Encoding</code>`
407407
<li>`<code title="">Upgrade</code>`
408-
<li>`<code title="">User-Agent</code>`
409408
<li>`<code title="">Via</code>`
410409
</ul>
411410

@@ -2321,12 +2320,12 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">5.4 </span>HTTP-network
23212320

23222321
<ol>
23232322
<li>
2324-
<p>Let <var title="">HTTPRequest</var> be <var title="">request</var> if
2323+
<p>Let <var title="">httpRequest</var> be <var title="">request</var> if
23252324
<var title="">request</var>'s <a href="#concept-request-window" title="concept-request-window">window</a> is
23262325
"<code>no-window</code>" and <var title="">request</var>'s
23272326
<a href="#concept-request-redirect-mode" title="concept-request-redirect-mode">redirect mode</a> is not
23282327
"<code>follow</code>", and a copy of <var title="">request</var>, with
2329-
<var title="">HTTPRequest</var>'s <a href="#concept-request-body" title="concept-request-body">body</a> being a tee
2328+
<var title="">httpRequest</var>'s <a href="#concept-request-body" title="concept-request-body">body</a> being a tee
23302329
of <var title="">request</var>'s <a href="#concept-request-body" title="concept-request-body">body</a>, otherwise.
23312330

23322331
<p class="note no-backref">A <var title="">request</var> is typically copied as it needs to
@@ -2337,14 +2336,14 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">5.4 </span>HTTP-network
23372336

23382337
<li><p>Let <var title="">contentLengthValue</var> be null.
23392338

2340-
<li><p>If <var title="">request</var>'s <a href="#concept-request-body" title="concept-request-body">body</a> is null
2341-
and <var title="">request</var>'s <a href="#concept-request-method" title="concept-request-method">method</a> is
2342-
`<code title="">HEAD</code>`, `<code title="">POST</code>`, or `<code title="">PUT</code>`, set
2339+
<li><p>If <var title="">httpRequest</var>'s <a href="#concept-request-body" title="concept-request-body">body</a> is
2340+
null and <var title="">httpRequest</var>'s <a href="#concept-request-method" title="concept-request-method">method</a>
2341+
is `<code title="">HEAD</code>`, `<code title="">POST</code>`, or `<code title="">PUT</code>`, set
23432342
<var title="">contentLengthValue</var> to `<code title="">0</code>`.
23442343
<!-- https://chromium.googlesource.com/chromium/src/+/ca9d6916c5fedf6f0ee73dfc397cb0f65ad326b9/net/http/http_network_transaction.cc#894 -->
23452344

2346-
<li><p>If <var title="">request</var>'s <a href="#concept-request-body" title="concept-request-body">body</a> is
2347-
non-null, set <var title="">contentLengthValue</var> to <var title="">request</var>'s
2345+
<li><p>If <var title="">httpRequest</var>'s <a href="#concept-request-body" title="concept-request-body">body</a> is
2346+
non-null, set <var title="">contentLengthValue</var> to <var title="">httpRequest</var>'s
23482347
<a href="#concept-request-body" title="concept-request-body">body</a>'s
23492348
<a href="#concept-body-length" title="concept-body-length">length</a>,
23502349
<a class="external" href="https://encoding.spec.whatwg.org/#utf-8-encode" title="utf-8 encode">utf-8 encoded</a>.
@@ -2353,37 +2352,65 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">5.4 </span>HTTP-network
23532352
<li><p>If <var title="">contentLengthValue</var> is non-null,
23542353
<a href="#concept-header-list-append" title="concept-header-list-append">append</a>
23552354
`<code title="">Content-Length</code>`/<var title="">contentLengthValue</var> to
2356-
<var title="">HTTPRequest</var>'s
2355+
<var title="">httpRequest</var>'s
23572356
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>.
23582357

23592358
<li><p><a href="#concept-header-list-append" title="concept-header-list-append">Append</a>
2360-
`<code title="">Referer</code>`/empty byte sequence, if <var title="">HTTPRequest</var>'s
2359+
`<code title="">Referer</code>`/empty byte sequence, if <var title="">httpRequest</var>'s
23612360
<a href="#concept-request-referrer" title="concept-request-referrer">referrer</a> is "<code>no-referrer</code>", and
2362-
`<code title="">Referer</code>`/<var title="">HTTPRequest</var>'s
2361+
`<code title="">Referer</code>`/<var title="">httpRequest</var>'s
23632362
<a href="#concept-request-referrer" title="concept-request-referrer">referrer</a>,
23642363
<a class="external" href="https://url.spec.whatwg.org/#concept-url-serializer" title="concept-url-serializer">serialized</a> and
23652364
<a class="external" href="https://encoding.spec.whatwg.org/#utf-8-encode" title="utf-8 encode">utf-8 encoded</a>, otherwise, to
2366-
<var title="">HTTPRequest</var>'s
2365+
<var title="">httpRequest</var>'s
23672366
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>.
23682367
<!-- XXX ideally we have an easier way to convert something ASCII-safe into bytes
23692368
concept-as-bytes -->
23702369

2371-
<li><p>If <var title="">HTTPRequest</var>'s
2370+
<li><p>If <var title="">httpRequest</var>'s
23722371
<a href="#force-origin-header-flag">force-<code>Origin</code>-header flag</a> is set,
23732372
<a href="#concept-header-list-append" title="concept-header-list-append">append</a>
2374-
`<code title="">Origin</code>`/<var title="">HTTPRequest</var>'s
2373+
`<code title="">Origin</code>`/<var title="">httpRequest</var>'s
23752374
<a href="#concept-request-origin" title="concept-request-origin">origin</a>,
23762375
<a class="external" href="https://html.spec.whatwg.org/multipage/browsers.html#ascii-serialisation-of-an-origin" title="ASCII serialization of an origin">serialized</a>
23772376
and <a class="external" href="https://encoding.spec.whatwg.org/#utf-8-encode" title="utf-8 encode">utf-8 encoded</a>, to
2378-
<var title="">HTTPRequest</var>'s
2377+
<var title="">httpRequest</var>'s
23792378
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>.
23802379
<!-- XXX concept-as-bytes -->
23812380

2381+
<li><p>If <var title="">httpRequest</var>'s
2382+
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> does not contain a
2383+
<a href="#concept-header" title="concept-header">header</a> whose
2384+
<a href="#concept-header-name" title="concept-header-name">name</a> is
2385+
`<code title="http-user-agent">User-Agent</code>`, user agents should
2386+
<a href="#concept-header-list-append" title="concept-header-list-append">append</a>
2387+
`<code>User-Agent</code>`/an appropriate <a href="#concept-header-value" title="concept-header-value">value</a> to
2388+
<var title="">httpRequest</var>'s
2389+
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>.
2390+
2391+
<li>
2392+
<p>Modify <var title="">httpRequest</var>'s
2393+
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> per HTTP.
2394+
2395+
<p class="note no-backref">It would be great if we could make this more normative
2396+
somehow. At this point <a href="#concept-header" title="concept-header">headers</a> such as
2397+
`<code title="http-accept-encoding">Accept-Encoding</code>`,
2398+
`<code title="http-connection">Connection</code>`,
2399+
`<code title="http-dnt">DNT</code>`, and
2400+
`<code title="http-host">Host</code>`,
2401+
are to be <a href="#concept-header-list-append" title="concept-header-list-append">appended</a> if necessary.
2402+
2403+
<p>`<code title="http-accept-charset">Accept-Charset</code>` must not be included.
2404+
`<code title="http-accept">Accept</code>` and
2405+
`<code title="http-accept-language">Accept-Language</code>` are already included at this
2406+
point (unless <code title="dom-global-fetch"><a href="#dom-global-fetch">fetch()</a></code> is used, which can omit them).
2407+
<span class="note">See <a href="#http-header-layer-division">HTTP header layer division</a>.</span>
2408+
23822409
<li>
23832410
<p>If <var title="">credentials flag</var> is set, run these substeps:
23842411

23852412
<ol>
2386-
<li><p>Modify <var title="">HTTPRequest</var>'s
2413+
<li><p>Modify <var title="">httpRequest</var>'s
23872414
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>
23882415
per HTTP State Management Mechanism.
23892416
<a href="#refsCOOKIES">[COOKIES]</a>
@@ -2392,108 +2419,95 @@ <h3 id="http-network-or-cache-fetch"><span class="secno">5.4 </span>HTTP-network
23922419
<!-- https://wiki.whatwg.org/wiki/HTTP_Authentication -->
23932420
<li><p>Let <var title="">authorizationValue</var> be null.
23942421

2395-
<li><p>If there's an <a href="#authentication-entry">authentication entry</a> for <var title="">HTTPRequest</var>
2396-
and either <var title="">HTTPRequest</var>'s
2422+
<li><p>If there's an <a href="#authentication-entry">authentication entry</a> for <var title="">httpRequest</var>
2423+
and either <var title="">httpRequest</var>'s
23972424
<a href="#concept-request-use-url-credentials-flag" title="concept-request-use-url-credentials-flag">use-URL-credentials flag</a> is
2398-
unset or <var title="">HTTPRequest</var>'s
2425+
unset or <var title="">httpRequest</var>'s
23992426
<a href="#concept-request-current-url" title="concept-request-current-url">current url</a> does not
24002427
<a class="external" href="https://url.spec.whatwg.org/#include-credentials">include credentials</a>, set
24012428
<var title="">authorizationValue</var> to <a href="#authentication-entry">authentication entry</a>.
24022429
<!-- need to define the cache concept -->
24032430

2404-
<li><p>Otherwise, if <var title="">HTTPRequest</var>'s
2431+
<li><p>Otherwise, if <var title="">httpRequest</var>'s
24052432
<a href="#concept-request-current-url" title="concept-request-current-url">current url</a> does
24062433
<a class="external" href="https://url.spec.whatwg.org/#include-credentials">include credentials</a> and the
24072434
<i title="">authentication-fetch flag</i> is set, set
2408-
<var title="">authorizationValue</var> to <var title="">HTTPRequest</var>'s
2435+
<var title="">authorizationValue</var> to <var title="">httpRequest</var>'s
24092436
<a href="#concept-request-current-url" title="concept-request-current-url">current url</a>,
24102437
<span class="XXX">converted to an `<code title="">Authorization</code>` value</span>.
24112438

24122439
<li><p>If <var title="">authorizationValue</var> is non-null,
24132440
<a href="#concept-header-list-append" title="concept-header-list-append">append</a>
24142441
`<code title="">Authorization</code>`/<var title="">authorizationValue</var> to
2415-
<var title="">HTTPRequest</var>'s
2442+
<var title="">httpRequest</var>'s
24162443
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>.
24172444
</ol>
24182445

24192446
<li>
24202447
<p>If there's a <a href="#proxy-authentication-entry">proxy-authentication entry</a>, use it as appropriate.
24212448

24222449
<p class="note no-backref">This intentionally does not depend on
2423-
<var title="">HTTPRequest</var>'s
2450+
<var title="">httpRequest</var>'s
24242451
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a>.
24252452

24262453
<li><p>Let <var title="">response</var> be null.
24272454

24282455
<li>
2429-
<p>If <var title="">request</var>'s
2456+
<p>If <var title="">httpRequest</var>'s
24302457
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is neither
24312458
"<code title="">no-store</code>" nor "<code title="">reload</code>", and there is a <em>complete</em>
24322459
<a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
2433-
<var title="">request</var> run these substeps:
2460+
<var title="">httpRequest</var> run these substeps:
24342461
<!-- XXX xref "HTTP cache" -->
24352462

24362463
<ol>
2437-
<li><p>If <var title="">request</var>'s
2464+
<li><p>If <var title="">httpRequest</var>'s
24382465
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is either
24392466
"<code title="">force-cache</code>" or "<code title="">only-if-cached</code>", set <var title="">response</var>
24402467
to the <a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
2441-
<var title="">request</var>.
2468+
<var title="">httpRequest</var>.
24422469

2443-
<li><p>Otherwise, if <var title="">request</var>'s
2470+
<li><p>Otherwise, if <var title="">httpRequest</var>'s
24442471
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is "<code title="">default</code>" and
24452472
the <a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
2446-
<var title="">request</var> does not require revalidation, set <var title="">response</var>
2447-
to that <a href="#concept-response" title="concept-response">response</a> and set
2473+
<var title="">httpRequest</var> does not require revalidation, set
2474+
<var title="">response</var> to that <a href="#concept-response" title="concept-response">response</a> and set
24482475
<var title="">response</var>'s <a href="#concept-response-cache-state" title="concept-response-cache-state">cache state</a>
24492476
to "<code title="">local</code>".
24502477
<!-- XXX xref "revalidation" -->
24512478

2452-
<li><p>Otherwise, if <var title="">request</var>'s
2479+
<li><p>Otherwise, if <var title="">httpRequest</var>'s
24532480
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is either "<code title="">default</code>"
24542481
or "<code title="">no-cache</code>", and the <a href="#concept-response" title="concept-response">response</a> in the
2455-
HTTP cache for <var title="">request</var> does require revalidation, modify
2456-
<var title="">HTTPRequest</var>'s
2482+
HTTP cache for <var title="">httpRequest</var> does require revalidation, modify
2483+
<var title="">httpRequest</var>'s
24572484
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> with revalidation
24582485
<a href="#concept-header" title="concept-header">headers</a>.
24592486
<!-- XXX modify, revalidation headers -->
24602487
</ol>
24612488

2462-
<li><p>Otherwise, if <var title="">request</var>'s
2463-
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is either "<code title="">default</code>"
2464-
or "<code title="">force-cache</code>", and there is a <em>partial</em>
2465-
<a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
2466-
<var title="">request</var>, modify <var title="">HTTPRequest</var>'s
2489+
<li><p>Otherwise, if <var title="">httpRequest</var>'s
2490+
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is either
2491+
"<code title="">default</code>" or "<code title="">force-cache</code>", and there is a
2492+
<em>partial</em> <a href="#concept-response" title="concept-response">response</a> in the HTTP cache for
2493+
<var title="">httpRequest</var>, modify <var title="">httpRequest</var>'s
24672494
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> with resume
24682495
<a href="#concept-header" title="concept-header">headers</a>.
24692496
<!-- XXX xref partial, modify, resume headers -->
24702497

2471-
<li>If <var title="">response</var> is null and <var title="">request</var>'s
2472-
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is "<code title="">only-if-cached</code>",
2473-
return a <a href="#concept-network-error" title="concept-network-error">network error</a>.
2474-
24752498
<li>
2476-
<p>If <var title="">response</var> is null, modify <var title="">HTTPRequest</var>'s
2477-
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a> per HTTP.
2478-
2479-
<p class="note no-backref">It would be great if we could make this more normative
2480-
somehow. At this point <a href="#concept-header" title="concept-header">headers</a> such as
2481-
`<code title="http-accept-encoding">Accept-Encoding</code>`,
2482-
`<code title="http-connection">Connection</code>`,
2483-
`<code title="http-dnt">DNT</code>`, and
2484-
`<code title="http-host">Host</code>`,
2485-
are to be <a href="#concept-header-list-append" title="concept-header-list-append">appended</a> if necessary.
2499+
<p>If <var title="">response</var> is null, run these substeps:
24862500

2487-
<p>`<code title="http-accept-charset">Accept-Charset</code>` must not be included.
2488-
`<code title="http-accept">Accept</code>` and
2489-
`<code title="http-accept-language">Accept-Language</code>` are already included at this
2490-
point (unless <code title="dom-global-fetch"><a href="#dom-global-fetch">fetch()</a></code> is used, which can omit them).
2491-
<span class="note">See <a href="#http-header-layer-division">HTTP header layer division</a>.</span>
2501+
<ol>
2502+
<li><p>If <var title="">httpRequest</var>'s
2503+
<a href="#concept-request-cache-mode" title="concept-request-cache-mode">cache mode</a> is
2504+
"<code title="">only-if-cached</code>", return a
2505+
<a href="#concept-network-error" title="concept-network-error">network error</a>.
24922506

2493-
<li>
2494-
<p>If <var title="">response</var> is null, set <var title="">response</var> to the result of
2495-
making an <a href="#concept-http-network-fetch" title="concept-http-network-fetch">HTTP-network fetch</a> using
2496-
<var title="">HTTPRequest</var> with the <i title="">credentials flag</i> set if set.
2507+
<li><p>Set <var title="">response</var> to the result of making an
2508+
<a href="#concept-http-network-fetch" title="concept-http-network-fetch">HTTP-network fetch</a> using
2509+
<var title="">httpRequest</var> with the <i title="">credentials flag</i> set if set.
2510+
</ol>
24972511

24982512
<li><p>Return <var title="">response</var>. <span class="note no-backref">Typically
24992513
<var title="">response</var>'s <a href="#concept-response-body" title="concept-response-body">body</a> is still being

0 commit comments

Comments
 (0)