Skip to content
Myr

Fix response details getting lost when using `onDownloadProgress` (#441)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yixuan Xu · committed by GitHub · parent e4077b9 · Browse files · 2 files+43 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+43 added−1 removed

  • tests:+37 added−0 removed
  • other:+6 added−1 removed

2 files+43 added−1 removed

modified:source/core/Ky.ts+6 added-1 removed
165 unmodified lines
166167 // To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one168 if (169 ((supportsFormData && this._options.body instanceof globalThis.FormData)170 || this._options.body instanceof URLSearchParams) && !(this._options.headers && (this._options.headers as Record<string, string>)['content-type'])170 || this._options.body instanceof URLSearchParams) && !(this._options.headers && (this._options.headers as Record<string, string>)['content-type'])171 ) {172 this.request.headers.delete('content-type');173 }174
138 unmodified lines
313314 await read();315 },316 }),317 {318 status: response.status,319 statusText: response.statusText,320 headers: response.headers,321 },322 );323 }324}
modified:test/browser.ts+37 added
89 unmodified lines
9091 await server.close();92});9394test('should copy origin response info when use onDownloadProgress', withPage, async (t: ExecutionContext, page: Page) => {95 const json = {hello: 'world'};96 const status = 202;97 const statusText = 'Accepted';98 const server = await createEsmTestServer();99 server.get('/', (_request, response) => {100 response.end('meow');101 });102103 server.get('/test', (_request, response) => {104 setTimeout(() => {105 response.statusMessage = statusText;106 response.status(status).header('X-ky-Header', 'ky').json(json);107 }, 500);108 });109 await page.goto(server.url);110 await addKyScriptToPage(page);111 const data = await page.evaluate(async url => {112 // eslint-disable-next-line @typescript-eslint/no-empty-function113 const request = window.ky.get(`${url}/test`, {onDownloadProgress() {}}).then(async v => ({114 headers: v.headers.get('X-ky-Header'),115 status: v.status,116 statusText: v.statusText,117 data: await v.json(),118 }));119 return request;120 }, server.url);121122 t.deepEqual(data, {123 status,124 headers: 'ky',125 statusText,126 data: json,127 });128 await server.close();129});130131test('aborting a request with onDonwloadProgress', withPage, async (t: ExecutionContext, page: Page) => {132 const server = await createEsmTestServer();133134 server.get('/', (_request, response) => {
335 unmodified lines