@@ -91,7 +91,7 @@ test('aborting a request', withPage, async (t: ExecutionContext, page: Page) =>
91
91
await server . close ( ) ;
92
92
} ) ;
93
93
94
- test ( 'should copy origin response info when use onDownloadProgress' , withPage , async ( t : ExecutionContext , page : Page ) => {
94
+ test ( 'should copy origin response info when using ` onDownloadProgress` ' , withPage , async ( t : ExecutionContext , page : Page ) => {
95
95
const json = { hello : 'world' } ;
96
96
const status = 202 ;
97
97
const statusText = 'Accepted' ;
@@ -128,6 +128,58 @@ test('should copy origin response info when use onDownloadProgress', withPage, a
128
128
await server . close ( ) ;
129
129
} ) ;
130
130
131
+ test ( 'should not copy response body with 204 status code when using `onDownloadProgress` ' , withPage , async ( t : ExecutionContext , page : Page ) => {
132
+ const status = 204 ;
133
+ const statusText = 'No content' ;
134
+ const server = await createEsmTestServer ( ) ;
135
+ server . get ( '/' , ( _request , response ) => {
136
+ response . end ( 'meow' ) ;
137
+ } ) ;
138
+
139
+ server . get ( '/test' , ( _request , response ) => {
140
+ setTimeout ( ( ) => {
141
+ response . statusMessage = statusText ;
142
+ response . status ( status ) . header ( 'X-ky-Header' , 'ky' ) . end ( null ) ;
143
+ } , 500 ) ;
144
+ } ) ;
145
+ await page . goto ( server . url ) ;
146
+ await addKyScriptToPage ( page ) ;
147
+ const data = await page . evaluate ( async ( url : string ) => {
148
+ const progress : any = [ ] ;
149
+ let totalBytes = 0 ;
150
+ const response = await window . ky . get ( `${ url } /test` , {
151
+ onDownloadProgress ( progressEvent ) {
152
+ progress . push ( progressEvent ) ;
153
+ } ,
154
+ } ) . then ( async v => {
155
+ totalBytes = Number ( v . headers . get ( 'content-length' ) ) || 0 ;
156
+ return ( {
157
+ headers : v . headers . get ( 'X-ky-Header' ) ,
158
+ status : v . status ,
159
+ statusText : v . statusText ,
160
+ } ) ;
161
+ } ) ;
162
+ return {
163
+ response,
164
+ progress,
165
+ totalBytes,
166
+ } ;
167
+ } , server . url ) ;
168
+
169
+ t . deepEqual ( data . response , {
170
+ status,
171
+ headers : 'ky' ,
172
+ statusText,
173
+ } ) ;
174
+ t . deepEqual ( data . progress , [ {
175
+ percent : 1 ,
176
+ totalBytes : data . totalBytes ,
177
+ transferredBytes : 0 ,
178
+ } ] ) ;
179
+
180
+ await server . close ( ) ;
181
+ } ) ;
182
+
131
183
test ( 'aborting a request with onDonwloadProgress' , withPage , async ( t : ExecutionContext , page : Page ) => {
132
184
const server = await createEsmTestServer ( ) ;
133
185
0 commit comments