@@ -2950,9 +2950,10 @@ and a <a for=/>response</a> <var>response</var>, is to run these steps:
2950
2950
false.
2951
2951
<!-- TODO Integrate https://wicg.github.io/background-fetch/#validate-a-partial-response into Fetch -->
2952
2952
2953
- <li><p> Wait for 1024 bytes of <var> response</var> 's <a for=response>body</a> or end-of-file,
2954
- whichever comes first and let <var> bytes</var> be those bytes.
2955
- <!-- TODO Obtaining these bytes needs to be defined in terms of a transform stream. -->
2953
+ <li><p> Let <var> bytes</var> be the result of running
2954
+ <a>obtain a copy of the first 1024 bytes of response</a> given <var> response</var> .
2955
+
2956
+ <li><p> If <var> bytes</var> is failure, then return false.
2956
2957
2957
2958
<li>
2958
2959
<p> If the <a>audio or video type pattern matching algorithm</a> given <var> bytes</var> does not
@@ -2990,6 +2991,79 @@ and a <a for=/>response</a> <var>response</var>, is to run these steps:
2990
2991
<li><p> If <var> mimeType</var> 's <a for="MIME type">essence</a> <a for=string>starts with</a>
2991
2992
"<code> audio/</code> ", "<code> image/</code> ", or "<code> video/</code> ", then return false.
2992
2993
2994
+ <li><p> Return <a>determine if response is JavaScript and not JSON</a> given <var> response</var> .
2995
+ </ol>
2996
+
2997
+ <hr>
2998
+
2999
+ <p> To <dfn>obtain a copy of the first 1024 bytes of response</dfn> , given a <a for=/>response</a>
3000
+ <var> response</var> , run these steps:
3001
+
3002
+ <ol>
3003
+ <li><p> Let <var> first1024Bytes</var> be null.
3004
+
3005
+ <li>
3006
+ <p> <a for=/>In parallel</a> :
3007
+
3008
+ <ol>
3009
+ <li><p> Let <var> bytes</var> be the empty <a for=/>byte sequence</a> .
3010
+
3011
+ <li><p> Let <var> transformStream</var> be a new {{TransformStream}} .
3012
+
3013
+ <li>
3014
+ <p> Let <var> transformAlgorithm</var> given a <var> chunk</var> be these steps:
3015
+
3016
+ <ol>
3017
+ <li><p> <a for=ReadableStream>Enqueue</a> <var> chunk</var> in <var> transformStream</var> .
3018
+
3019
+ <li>
3020
+ <p> If <var> first1024Bytes</var> is null, then:
3021
+
3022
+ <ol>
3023
+ <li><p> Let <var> chunkBytes</var> be
3024
+ <a lt="get a copy of the bytes held by the buffer source">a copy of the bytes held by</a>
3025
+ <var> chunk</var> .
3026
+
3027
+ <li><p> Append <var> chunkBytes</var> to <var> bytes</var> .
3028
+
3029
+ <li>
3030
+ <p> If <var> bytes</var> 's <a for="byte sequencue">length</a> is greater than 1024, then:
3031
+
3032
+ <ol>
3033
+ <li><p> Truncate <var> bytes</var> from the end so that it only contains 1024 bytes.
3034
+
3035
+ <li><p> Set <var> first1024Bytes</var> to <var> bytes</var> .
3036
+ </ol>
3037
+ </ol>
3038
+ </ol>
3039
+
3040
+ <li><p> Let <var> flushAlgorithm</var> be this step: if <var> first1024Bytes</var> is null, then set
3041
+ <var> first1024Bytes</var> to <var> bytes</var> .
3042
+
3043
+ <li><p> <a for=TransformStream>Set up</a> <var> transformStream</var> with
3044
+ <a for="TransformStream/set up"><i>transformAlgorithm</i></a> set to
3045
+ <var> transformAlgorithm</var> and <a for="TransformStream/set up"><i>flushAlgorithm</i></a> set
3046
+ to <var> flushAlgorithm</var> .
3047
+
3048
+ <li><p> Set <var> response</var> 's <a for=response>body</a>' s <a for=body>stream</a> to the result
3049
+ of <var> response</var> 's <a for=response>body</a>' s <a for=body>stream</a>
3050
+ <a for=TransformStream>piped through</a> <var> transformStream</var> .
3051
+ </ol>
3052
+
3053
+ <li><p> Wait until <var> first1024Bytes</var> is non-null or <var> response</var> 's
3054
+ <a for=response>body</a> 's <a for=body>stream</a> is <a for=ReadableStream>errored</a> .
3055
+
3056
+ <li><p> If <var> first1024Bytes</var> is null, then return failure.
3057
+
3058
+ <li> Return <var> first1024Bytes</var> .
3059
+ </ol>
3060
+
3061
+ <hr>
3062
+
3063
+ <p> To <dfn>determine if response is JavaScript and not JSON</dfn> given a <a for=/>response</a>
3064
+ <var> response</var> , run these steps:</p>
3065
+
3066
+ <ol>
2993
3067
<li><p> Let <var> responseBodyBytes</var> be null.
2994
3068
2995
3069
<li>
@@ -3013,8 +3087,11 @@ and a <a for=/>response</a> <var>response</var>, is to run these steps:
3013
3087
3014
3088
<li><p> <a for=/>Assert</a> : <var> responseBodyBytes</var> is a <a for=/>byte sequence</a> .
3015
3089
3016
- <li><p> If <a>parse JSON bytes to a JavaScript value</a> given <var> responseBodyBytes</var> does not
3017
- throw, then return false. If it throws, catch the exception and ignore it.
3090
+ <li>
3091
+ <p> If <a>parse JSON bytes to a JavaScript value</a> given <var> responseBodyBytes</var> does not
3092
+ throw, then return false. If it throws, catch the exception and ignore it.
3093
+
3094
+ <p class=note> If there is an exception, <var> response</var> is not JSON. If there is not, it is.
3018
3095
3019
3096
<li><p> Let <var> sourceText</var> be the result of <a for=/>decoding</a>
3020
3097
<var> responseBodyBytes</var> given <var> request</var> 's
0 commit comments