feat(route): add maxRedirects option to Route.fetch (#20567)
References #20501.
This commit is contained in:
parent
0edf77fe91
commit
6ad4687f4d
|
|
@ -488,6 +488,9 @@ await page.RouteAsync("https://dog.ceo/api/breeds/list/all", async route =>
|
||||||
|
|
||||||
If set changes the request URL. New URL must have same protocol as original one.
|
If set changes the request URL. New URL must have same protocol as original one.
|
||||||
|
|
||||||
|
### option: Route.fetch.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
|
||||||
|
* since: v1.31
|
||||||
|
|
||||||
### option: Route.fetch.method
|
### option: Route.fetch.method
|
||||||
* since: v1.29
|
* since: v1.29
|
||||||
- `method` <[string]>
|
- `method` <[string]>
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ export class Route extends ChannelOwner<channels.RouteChannel> implements api.Ro
|
||||||
this._reportHandled(true);
|
this._reportHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetch(options: FallbackOverrides = {}) {
|
async fetch(options: FallbackOverrides & { maxRedirects?: number } = {}): Promise<APIResponse> {
|
||||||
return await this._wrapApiCall(async () => {
|
return await this._wrapApiCall(async () => {
|
||||||
const context = this.request()._context();
|
const context = this.request()._context();
|
||||||
return context.request._innerFetch({ request: this.request(), data: options.postData, ...options });
|
return context.request._innerFetch({ request: this.request(), data: options.postData, ...options });
|
||||||
|
|
|
||||||
6
packages/playwright-core/types/types.d.ts
vendored
6
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -17924,6 +17924,12 @@ export interface Route {
|
||||||
*/
|
*/
|
||||||
headers?: { [key: string]: string; };
|
headers?: { [key: string]: string; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is
|
||||||
|
* exceeded. Defaults to `20`. Pass `0` to not follow redirects.
|
||||||
|
*/
|
||||||
|
maxRedirects?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set changes the request method (e.g. GET or POST).
|
* If set changes the request method (e.g. GET or POST).
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,21 @@ it('should fulfill intercepted response using alias', async ({ page, server, isE
|
||||||
expect(response.headers()['content-type']).toContain('text/html');
|
expect(response.headers()['content-type']).toContain('text/html');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not follow redirects when maxRedirects is set to 0 in route.fetch', async ({ page, server, isAndroid, isElectron }) => {
|
||||||
|
it.fixme(isElectron, 'error: Browser context management is not supported.');
|
||||||
|
it.skip(isAndroid, 'The internal Android localhost (10.0.0.2) != the localhost on the host');
|
||||||
|
|
||||||
|
server.setRedirect('/foo', '/empty.html');
|
||||||
|
await page.route('**/*', async route => {
|
||||||
|
const response = await route.fetch({ maxRedirects: 0 });
|
||||||
|
expect(response.headers()['location']).toBe('/empty.html');
|
||||||
|
expect(response.status()).toBe(302);
|
||||||
|
await route.fulfill({ body: 'hello' });
|
||||||
|
});
|
||||||
|
await page.goto(server.PREFIX + '/foo');
|
||||||
|
expect(await page.content()).toContain('hello');
|
||||||
|
});
|
||||||
|
|
||||||
it('should intercept with url override', async ({ page, server, isElectron, isAndroid }) => {
|
it('should intercept with url override', async ({ page, server, isElectron, isAndroid }) => {
|
||||||
it.fixme(isElectron, 'error: Browser context management is not supported.');
|
it.fixme(isElectron, 'error: Browser context management is not supported.');
|
||||||
it.skip(isAndroid, 'The internal Android localhost (10.0.0.2) != the localhost on the host');
|
it.skip(isAndroid, 'The internal Android localhost (10.0.0.2) != the localhost on the host');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue