mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-06 03:16:17 +03:00
fix: fulfill with unassigned status codes (#30856)
Fixes https://github.com/microsoft/playwright/issues/30773
This commit is contained in:
parent
4ad94c1a8c
commit
b375f10778
@ -317,7 +317,7 @@ export class CRNetworkManager {
|
||||
requestPausedSessionInfo!.session._sendMayFail('Fetch.fulfillRequest', {
|
||||
requestId: requestPausedEvent.requestId,
|
||||
responseCode: 204,
|
||||
responsePhrase: network.STATUS_TEXTS['204'],
|
||||
responsePhrase: network.statusText(204),
|
||||
responseHeaders,
|
||||
body: '',
|
||||
});
|
||||
@ -622,7 +622,7 @@ class RouteImpl implements network.RouteDelegate {
|
||||
await this._session.send('Fetch.fulfillRequest', {
|
||||
requestId: this._interceptionId!,
|
||||
responseCode: response.status,
|
||||
responsePhrase: network.STATUS_TEXTS[String(response.status)],
|
||||
responsePhrase: network.statusText(response.status),
|
||||
responseHeaders,
|
||||
body,
|
||||
});
|
||||
|
@ -242,7 +242,7 @@ class FFRouteImpl implements network.RouteDelegate {
|
||||
await this._session.sendMayFail('Network.fulfillInterceptedRequest', {
|
||||
requestId: this._request._id,
|
||||
status: response.status,
|
||||
statusText: network.STATUS_TEXTS[String(response.status)] || '',
|
||||
statusText: network.statusText(response.status),
|
||||
headers: response.headers,
|
||||
base64body,
|
||||
});
|
||||
|
@ -616,7 +616,7 @@ export interface RouteDelegate {
|
||||
}
|
||||
|
||||
// List taken from https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml with extra 306 and 418 codes.
|
||||
export const STATUS_TEXTS: { [status: string]: string } = {
|
||||
const STATUS_TEXTS: { [status: string]: string } = {
|
||||
'100': 'Continue',
|
||||
'101': 'Switching Protocols',
|
||||
'102': 'Processing',
|
||||
@ -682,6 +682,10 @@ export const STATUS_TEXTS: { [status: string]: string } = {
|
||||
'511': 'Network Authentication Required',
|
||||
};
|
||||
|
||||
export function statusText(status: number): string {
|
||||
return STATUS_TEXTS[String(status)] || 'Unknown';
|
||||
}
|
||||
|
||||
export function singleHeader(name: string, value: string): HeadersArray {
|
||||
return [{ name, value }];
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ export class WKRouteImpl implements network.RouteDelegate {
|
||||
await this._session.sendMayFail('Network.interceptRequestWithResponse', {
|
||||
requestId: this._requestId,
|
||||
status: response.status,
|
||||
statusText: network.STATUS_TEXTS[String(response.status)],
|
||||
statusText: network.statusText(response.status),
|
||||
mimeType,
|
||||
headers,
|
||||
base64Encoded: response.isBase64,
|
||||
|
@ -78,8 +78,9 @@ it('should work with status code 422', async ({ page, server }) => {
|
||||
expect(await page.evaluate(() => document.body.textContent)).toBe('Yo, page!');
|
||||
});
|
||||
|
||||
it('should throw exception if status code is not supported', async ({ page, server, browserName }) => {
|
||||
it('should fulfill with unuassigned status codes', async ({ page, server, browserName }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/28490' });
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30773' });
|
||||
let fulfillPromiseCallback;
|
||||
const fulfillPromise = new Promise<Error|undefined>(f => fulfillPromiseCallback = f);
|
||||
await page.route('**/data.json', route => {
|
||||
@ -89,14 +90,14 @@ it('should throw exception if status code is not supported', async ({ page, serv
|
||||
}).catch(e => e));
|
||||
});
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
page.evaluate(url => fetch(url), server.PREFIX + '/data.json').catch(() => {});
|
||||
const response = await page.evaluate(async url => {
|
||||
const { status, statusText } = await fetch(url);
|
||||
return { status, statusText };
|
||||
}, server.PREFIX + '/data.json');
|
||||
const error = await fulfillPromise;
|
||||
if (browserName === 'chromium') {
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain(' Invalid http status code or phrase');
|
||||
} else {
|
||||
expect(error).toBe(undefined);
|
||||
}
|
||||
expect(error).toBe(undefined);
|
||||
expect(response.status).toBe(430);
|
||||
expect(response.statusText).toBe('Unknown');
|
||||
});
|
||||
|
||||
it('should not throw if request was cancelled by the page', async ({ page, server }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user