fix(fetch): correctly return empty response body (#9371)

This commit is contained in:
Yury Semikhatsky 2021-10-07 11:38:51 -07:00 committed by GitHub
parent ddbd64e4df
commit fb001f608f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -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) {

View file

@ -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');
});