fix(fetch): correctly return empty response body (#9371)
This commit is contained in:
parent
ddbd64e4df
commit
fb001f608f
|
|
@ -218,7 +218,7 @@ export class FetchResponse implements api.ApiResponse {
|
|||
return this._request._wrapApiCall(async (channel: channels.FetchRequestChannel) => {
|
||||
try {
|
||||
const result = await channel.fetchResponseBody({ fetchUid: this._fetchUid() });
|
||||
if (!result.binary)
|
||||
if (result.binary === undefined)
|
||||
throw new Error('Response has been disposed');
|
||||
return Buffer.from(result.binary!, 'base64');
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -158,3 +158,14 @@ it('should be able to construct with context options', async ({ playwright, serv
|
|||
const response = await request.get(server.EMPTY_PAGE);
|
||||
expect(response.ok()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return empty body', async ({ playwright, server }) => {
|
||||
const request = await playwright.request.newContext();
|
||||
const response = await request.get(server.EMPTY_PAGE);
|
||||
const body = await response.body();
|
||||
expect(body.length).toBe(0);
|
||||
expect(await response.text()).toBe('');
|
||||
await request.dispose();
|
||||
const error = await response.body().catch(e => e);
|
||||
expect(error.message).toContain('Response has been disposed');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue