File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,8 @@ export class Ky {
92
92
}
93
93
94
94
const contentLength = response . headers . get ( 'Content-Length' ) ;
95
- if ( contentLength === null || contentLength === '0' ) {
95
+ const transferEncoding = response . headers . get ( 'Transfer-Encoding' ) ;
96
+ if ( ( contentLength === null || contentLength === '0' ) && transferEncoding !== 'chunked' ) {
96
97
return '' ;
97
98
}
98
99
Original file line number Diff line number Diff line change @@ -236,6 +236,22 @@ test('.json() with custom accept header', async t => {
236
236
await server . close ( ) ;
237
237
} ) ;
238
238
239
+ test ( '.json() when response is chunked' , async t => {
240
+ const server = await createHttpTestServer ( ) ;
241
+ server . get ( '/' , async ( request , response ) => {
242
+ response . write ( '[' ) ;
243
+ response . write ( '"one",' ) ;
244
+ response . write ( '"two"' ) ;
245
+ response . end ( ']' ) ;
246
+ } ) ;
247
+
248
+ const responseJson = await ky . get ( server . url ) . json ( ) ;
249
+
250
+ t . deepEqual ( responseJson , [ 'one' , 'two' ] ) ;
251
+
252
+ await server . close ( ) ;
253
+ } ) ;
254
+
239
255
test ( '.json() with invalid JSON body' , async t => {
240
256
const server = await createHttpTestServer ( ) ;
241
257
server . get ( '/' , async ( request , response ) => {
You can’t perform that action at this time.
0 commit comments