@@ -2304,18 +2304,29 @@ known as an <dfn export id=concept-aborted-network-error>aborted network error</
2304
2304
2305
2305
<hr>
2306
2306
2307
- <p> A <dfn export id=concept-filtered-response>filtered response</dfn> is a limited view on a
2308
- <a for=/>response</a> that is not a
2309
- <a>network error</a> . This
2310
- <a for=/>response</a> is referred to as the
2311
- <a>filtered response</a> 's associated
2312
- <dfn export id=concept-internal-response for="filtered response">internal response</dfn> .
2313
-
2314
- <p class="note no-backref"> The <a for=/>fetch</a> algorithm returns such a view to ensure APIs do
2315
- not accidentally leak information. If the information needs to be exposed for legacy reasons, e.g.,
2316
- to feed image data to a decoder, the associated <a for="filtered response">internal response</a> can
2317
- be used, which is only "accessible" to internal specification algorithms and is never a
2318
- <a>filtered response</a> itself.
2307
+ <p> A <dfn export id=concept-filtered-response>filtered response</dfn> is a <a for=/>response</a>
2308
+ that offers a limited view on an associated <a for=/>response</a> . This associated
2309
+ <a for=/>response</a> can be accessed through <a>filtered response</a> 's
2310
+ <dfn export id=concept-internal-response for="filtered response">internal response</dfn> (a
2311
+ <a for=/>response</a> that is neither a <a for=/>network error</a> nor a
2312
+ <a for=/>filtered response</a> ).
2313
+
2314
+ <p> Unless stated otherwise a <a for=/>filtered response</a> 's associated concepts (such as its
2315
+ <a for=response>body</a> ) refer to the associated concepts of its
2316
+ <a for="filtered response">internal response</a> . (The exceptions to this are listed below as part
2317
+ of defining the concrete types of <a for=/>filtered responses</a> .)
2318
+
2319
+ <div class=note>
2320
+ <p> The <a for=/>fetch</a> algorithm by way of <a for=fetch><i>processResponse</i></a> and
2321
+ equivalent parameters exposes <a for=/>filtered responses</a> to callers to ensure they do not
2322
+ accidentally leak information. If the information needs to be revealed for legacy reasons, e.g., to
2323
+ feed image data to a decoder, the associated <a for="filtered response">internal response</a> can
2324
+ be used by specification algorithms.
2325
+
2326
+ <p> New specifications ought not to build further on <a>opaque filtered responses</a> or
2327
+ <a>opaque-redirect filtered responses</a> . Those are legacy constructs and cannot always be
2328
+ adequately protected given contemporary computer architecture.
2329
+ </div>
2319
2330
2320
2331
<p> A <dfn export id=concept-filtered-response-basic>basic filtered response</dfn> is a
2321
2332
<a>filtered response</a> whose
@@ -2357,7 +2368,7 @@ is a <a>filtered response</a> whose
2357
2368
<a for=response>header list</a> is empty, and
2358
2369
<a for=response>body</a> is null.
2359
2370
2360
- <div class=" note no-backref" >
2371
+ <div class=note>
2361
2372
<p> Exposing the <a for=response>URL list</a> for
2362
2373
<a lt="opaque-redirect filtered response">opaque-redirect filtered responses</a> is harmless since
2363
2374
no redirects are followed.
@@ -2371,6 +2382,30 @@ is a <a>filtered response</a> whose
2371
2382
<a attribute for=Response lt=ok><code>response.ok</code></a> , will return rather useless results.
2372
2383
</div>
2373
2384
2385
+ <div class=example id=example-filtered-responses>
2386
+ <p> The <a for=response>type</a> of a <a for=/>response</a> is exposed to script through the
2387
+ {{Response/type}} getter:
2388
+
2389
+ <pre><code class=lang-javascript>
2390
+ console.log(new Response().type); // "default"
2391
+
2392
+ console.log((await fetch("/")).type); // "basic"
2393
+
2394
+ console.log((await fetch("https://api.example/status")).type); // "cors"
2395
+
2396
+ console.log((await fetch("https://crossorigin.example/image", { mode: "no-cors" })).type); // "opaque"
2397
+
2398
+ console.log((await fetch("/surprise-me", { redirect: "manual" })).type); // "opaqueredirect"
2399
+ </code></pre>
2400
+ <!-- "error" is exposed through Response.error().type, but seems like a design mistake as
2401
+ network errors are otherwise always exposed through a TypeError exception. -->
2402
+
2403
+ <p> (This assumes that the various resources exist, <code> https://api.example/status</code> has the
2404
+ appropriate CORS headers, and <code> /surprise-me</code> uses a <a>redirect status</a> .)
2405
+ </div>
2406
+
2407
+ <hr>
2408
+
2374
2409
<p> To <dfn export for=response id=concept-response-clone>clone</dfn> a
2375
2410
<a for=/>response</a> <var> response</var> , run these steps:
2376
2411
@@ -2390,6 +2425,8 @@ is a <a>filtered response</a> whose
2390
2425
<li><p> Return <var> newResponse</var> .
2391
2426
</ol>
2392
2427
2428
+ <hr>
2429
+
2393
2430
<p> A <dfn id=concept-fresh-response>fresh response</dfn> is a <a for=/>response</a> whose
2394
2431
<a href=https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.3>current age</a> is within its
2395
2432
<a href=https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.1>freshness lifetime</a> .
@@ -4403,9 +4440,8 @@ steps:
4403
4440
<li><p> Let <var> processBodyError</var> be this step: run <a>fetch response handover</a> given
4404
4441
<var> fetchParams</var> and a <a>network error</a> .
4405
4442
4406
- <li><p> If <var> request</var> 's <a for=request>response tainting</a> is "<code> opaque</code> " or
4407
- <var> response</var> 's <a for=response>body</a> is null, then run <var> processBodyError</var> and
4408
- abort these steps.
4443
+ <li><p> If <var> response</var> 's <a for=response>body</a> is null, then run
4444
+ <var> processBodyError</var> and abort these steps.
4409
4445
4410
4446
<li>
4411
4447
<p> Let <var> processBody</var> given <var> bytes</var> be these steps:
0 commit comments