Skip to content

Commit

Permalink
chore: make maxRedirects available in java, improve docs. tests (#17227)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Sep 9, 2022
1 parent 17b203a commit 24ee456
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 59 deletions.
80 changes: 40 additions & 40 deletions docs/src/api/class-apirequestcontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.delete.params = %%-csharp-fetch-option-params-%%
* since: v1.16
### option: APIRequestContext.delete.headers = %%-js-python-fetch-option-headers-%%
### option: APIRequestContext.delete.headers = %%-js-python-csharp-fetch-option-headers-%%
* since: v1.16
### option: APIRequestContext.delete.data = %%-js-python-fetch-option-data-%%
### option: APIRequestContext.delete.data = %%-js-python-csharp-fetch-option-data-%%
* since: v1.17
### option: APIRequestContext.delete.form = %%-js-python-fetch-option-form-%%
* since: v1.17
Expand All @@ -155,13 +155,13 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.17
### option: APIRequestContext.delete.multipart = %%-csharp-fetch-option-multipart-%%
* since: v1.17
### option: APIRequestContext.delete.timeout = %%-js-python-fetch-option-timeout-%%
### option: APIRequestContext.delete.timeout = %%-js-python-csharp-fetch-option-timeout-%%
* since: v1.16
### option: APIRequestContext.delete.failOnStatusCode = %%-js-python-fetch-option-failonstatuscode-%%
### option: APIRequestContext.delete.failOnStatusCode = %%-js-python-csharp-fetch-option-failonstatuscode-%%
* since: v1.16
### option: APIRequestContext.delete.ignoreHTTPSErrors = %%-js-python-fetch-option-ignorehttpserrors-%%
### option: APIRequestContext.delete.ignoreHTTPSErrors = %%-js-python-csharp-fetch-option-ignorehttpserrors-%%
* since: v1.16
### option: APIRequestContext.delete.maxRedirects = %%-js-python-fetch-option-maxredirects-%%
### option: APIRequestContext.delete.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
* since: v1.26

## async method: APIRequestContext.dispose
Expand Down Expand Up @@ -198,9 +198,9 @@ Target URL or Request to get all parameters from.
If set changes the fetch method (e.g. [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) or
[POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)). If not specified, GET method is used.

### option: APIRequestContext.fetch.headers = %%-js-python-fetch-option-headers-%%
### option: APIRequestContext.fetch.headers = %%-js-python-csharp-fetch-option-headers-%%
* since: v1.16
### option: APIRequestContext.fetch.data = %%-js-python-fetch-option-data-%%
### option: APIRequestContext.fetch.data = %%-js-python-csharp-fetch-option-data-%%
* since: v1.16
### option: APIRequestContext.fetch.form = %%-js-python-fetch-option-form-%%
* since: v1.16
Expand All @@ -210,13 +210,13 @@ If set changes the fetch method (e.g. [PUT](https://developer.mozilla.org/en-US/
* since: v1.16
### option: APIRequestContext.fetch.multipart = %%-csharp-fetch-option-multipart-%%
* since: v1.16
### option: APIRequestContext.fetch.timeout = %%-js-python-fetch-option-timeout-%%
### option: APIRequestContext.fetch.timeout = %%-js-python-csharp-fetch-option-timeout-%%
* since: v1.16
### option: APIRequestContext.fetch.failOnStatusCode = %%-js-python-fetch-option-failonstatuscode-%%
### option: APIRequestContext.fetch.failOnStatusCode = %%-js-python-csharp-fetch-option-failonstatuscode-%%
* since: v1.16
### option: APIRequestContext.fetch.ignoreHTTPSErrors = %%-js-python-fetch-option-ignorehttpserrors-%%
### option: APIRequestContext.fetch.ignoreHTTPSErrors = %%-js-python-csharp-fetch-option-ignorehttpserrors-%%
* since: v1.16
### option: APIRequestContext.fetch.maxRedirects = %%-js-python-fetch-option-maxredirects-%%
### option: APIRequestContext.fetch.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
* since: v1.26

## async method: APIRequestContext.get
Expand All @@ -235,15 +235,15 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.get.params = %%-csharp-fetch-option-params-%%
* since: v1.16
### option: APIRequestContext.get.headers = %%-js-python-fetch-option-headers-%%
### option: APIRequestContext.get.headers = %%-js-python-csharp-fetch-option-headers-%%
* since: v1.16
### option: APIRequestContext.get.timeout = %%-js-python-fetch-option-timeout-%%
### option: APIRequestContext.get.timeout = %%-js-python-csharp-fetch-option-timeout-%%
* since: v1.16
### option: APIRequestContext.get.failOnStatusCode = %%-js-python-fetch-option-failonstatuscode-%%
### option: APIRequestContext.get.failOnStatusCode = %%-js-python-csharp-fetch-option-failonstatuscode-%%
* since: v1.16
### option: APIRequestContext.get.ignoreHTTPSErrors = %%-js-python-fetch-option-ignorehttpserrors-%%
### option: APIRequestContext.get.ignoreHTTPSErrors = %%-js-python-csharp-fetch-option-ignorehttpserrors-%%
* since: v1.16
### option: APIRequestContext.get.maxRedirects = %%-js-python-fetch-option-maxredirects-%%
### option: APIRequestContext.get.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
* since: v1.26

## async method: APIRequestContext.head
Expand All @@ -262,15 +262,15 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.head.params = %%-csharp-fetch-option-params-%%
* since: v1.16
### option: APIRequestContext.head.headers = %%-js-python-fetch-option-headers-%%
### option: APIRequestContext.head.headers = %%-js-python-csharp-fetch-option-headers-%%
* since: v1.16
### option: APIRequestContext.head.timeout = %%-js-python-fetch-option-timeout-%%
### option: APIRequestContext.head.timeout = %%-js-python-csharp-fetch-option-timeout-%%
* since: v1.16
### option: APIRequestContext.head.failOnStatusCode = %%-js-python-fetch-option-failonstatuscode-%%
### option: APIRequestContext.head.failOnStatusCode = %%-js-python-csharp-fetch-option-failonstatuscode-%%
* since: v1.16
### option: APIRequestContext.head.ignoreHTTPSErrors = %%-js-python-fetch-option-ignorehttpserrors-%%
### option: APIRequestContext.head.ignoreHTTPSErrors = %%-js-python-csharp-fetch-option-ignorehttpserrors-%%
* since: v1.16
### option: APIRequestContext.head.maxRedirects = %%-js-python-fetch-option-maxredirects-%%
### option: APIRequestContext.head.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
* since: v1.26

## async method: APIRequestContext.patch
Expand All @@ -289,9 +289,9 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.patch.params = %%-csharp-fetch-option-params-%%
* since: v1.16
### option: APIRequestContext.patch.headers = %%-js-python-fetch-option-headers-%%
### option: APIRequestContext.patch.headers = %%-js-python-csharp-fetch-option-headers-%%
* since: v1.16
### option: APIRequestContext.patch.data = %%-js-python-fetch-option-data-%%
### option: APIRequestContext.patch.data = %%-js-python-csharp-fetch-option-data-%%
* since: v1.16
### option: APIRequestContext.patch.form = %%-js-python-fetch-option-form-%%
* since: v1.16
Expand All @@ -301,13 +301,13 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.patch.multipart = %%-csharp-fetch-option-multipart-%%
* since: v1.16
### option: APIRequestContext.patch.timeout = %%-js-python-fetch-option-timeout-%%
### option: APIRequestContext.patch.timeout = %%-js-python-csharp-fetch-option-timeout-%%
* since: v1.16
### option: APIRequestContext.patch.failOnStatusCode = %%-js-python-fetch-option-failonstatuscode-%%
### option: APIRequestContext.patch.failOnStatusCode = %%-js-python-csharp-fetch-option-failonstatuscode-%%
* since: v1.16
### option: APIRequestContext.patch.ignoreHTTPSErrors = %%-js-python-fetch-option-ignorehttpserrors-%%
### option: APIRequestContext.patch.ignoreHTTPSErrors = %%-js-python-csharp-fetch-option-ignorehttpserrors-%%
* since: v1.16
### option: APIRequestContext.patch.maxRedirects = %%-js-python-fetch-option-maxredirects-%%
### option: APIRequestContext.patch.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
* since: v1.26

## async method: APIRequestContext.post
Expand All @@ -326,9 +326,9 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.post.params = %%-csharp-fetch-option-params-%%
* since: v1.16
### option: APIRequestContext.post.headers = %%-js-python-fetch-option-headers-%%
### option: APIRequestContext.post.headers = %%-js-python-csharp-fetch-option-headers-%%
* since: v1.16
### option: APIRequestContext.post.data = %%-js-python-fetch-option-data-%%
### option: APIRequestContext.post.data = %%-js-python-csharp-fetch-option-data-%%
* since: v1.16
### option: APIRequestContext.post.form = %%-js-python-fetch-option-form-%%
* since: v1.16
Expand All @@ -338,13 +338,13 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.post.multipart = %%-csharp-fetch-option-multipart-%%
* since: v1.16
### option: APIRequestContext.post.timeout = %%-js-python-fetch-option-timeout-%%
### option: APIRequestContext.post.timeout = %%-js-python-csharp-fetch-option-timeout-%%
* since: v1.16
### option: APIRequestContext.post.failOnStatusCode = %%-js-python-fetch-option-failonstatuscode-%%
### option: APIRequestContext.post.failOnStatusCode = %%-js-python-csharp-fetch-option-failonstatuscode-%%
* since: v1.16
### option: APIRequestContext.post.ignoreHTTPSErrors = %%-js-python-fetch-option-ignorehttpserrors-%%
### option: APIRequestContext.post.ignoreHTTPSErrors = %%-js-python-csharp-fetch-option-ignorehttpserrors-%%
* since: v1.16
### option: APIRequestContext.post.maxRedirects = %%-js-python-fetch-option-maxredirects-%%
### option: APIRequestContext.post.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
* since: v1.26

## async method: APIRequestContext.put
Expand All @@ -363,9 +363,9 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.put.params = %%-csharp-fetch-option-params-%%
* since: v1.16
### option: APIRequestContext.put.headers = %%-js-python-fetch-option-headers-%%
### option: APIRequestContext.put.headers = %%-js-python-csharp-fetch-option-headers-%%
* since: v1.16
### option: APIRequestContext.put.data = %%-js-python-fetch-option-data-%%
### option: APIRequestContext.put.data = %%-js-python-csharp-fetch-option-data-%%
* since: v1.16
### option: APIRequestContext.put.form = %%-js-python-fetch-option-form-%%
* since: v1.16
Expand All @@ -375,13 +375,13 @@ context cookies from the response. The method will automatically follow redirect
* since: v1.16
### option: APIRequestContext.put.multipart = %%-csharp-fetch-option-multipart-%%
* since: v1.16
### option: APIRequestContext.put.timeout = %%-js-python-fetch-option-timeout-%%
### option: APIRequestContext.put.timeout = %%-js-python-csharp-fetch-option-timeout-%%
* since: v1.16
### option: APIRequestContext.put.failOnStatusCode = %%-js-python-fetch-option-failonstatuscode-%%
### option: APIRequestContext.put.failOnStatusCode = %%-js-python-csharp-fetch-option-failonstatuscode-%%
* since: v1.16
### option: APIRequestContext.put.ignoreHTTPSErrors = %%-js-python-fetch-option-ignorehttpserrors-%%
### option: APIRequestContext.put.ignoreHTTPSErrors = %%-js-python-csharp-fetch-option-ignorehttpserrors-%%
* since: v1.16
### option: APIRequestContext.put.maxRedirects = %%-js-python-fetch-option-maxredirects-%%
### option: APIRequestContext.put.maxRedirects = %%-js-python-csharp-fetch-option-maxredirects-%%
* since: v1.26

## async method: APIRequestContext.storageState
Expand Down
11 changes: 11 additions & 0 deletions docs/src/api/class-requestoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ Header value.

Whether to ignore HTTPS errors when sending network requests.

## method: RequestOptions.setMaxRedirects
* since: v1.26
- returns: <[RequestOptions]>

### param: RequestOptions.setMaxRedirects.maxRedirects
* since: v1.26
- `maxRedirects` <[int]>

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.

## method: RequestOptions.setMethod
* since: v1.18
- returns: <[RequestOptions]>
Expand Down
17 changes: 9 additions & 8 deletions docs/src/api/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,19 @@ Query parameters to be sent with the URL.

Optional request parameters.

## js-python-fetch-option-headers
## js-python-csharp-fetch-option-headers
* langs: js, python, csharp
- `headers` <[Object]<[string], [string]>>

Allows to set HTTP headers.

## js-python-fetch-option-timeout
## js-python-csharp-fetch-option-timeout
* langs: js, python, csharp
- `timeout` <[float]>

Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.

## js-python-fetch-option-failonstatuscode
## js-python-csharp-fetch-option-failonstatuscode
* langs: js, python, csharp
- `failOnStatusCode` <[boolean]>

Expand Down Expand Up @@ -384,25 +384,26 @@ or as file-like object containing file name, mime-type and its content.

An instance of [FormData] can be created via [`method: APIRequestContext.createFormData`].

## js-python-fetch-option-data
## js-python-csharp-fetch-option-data
* langs: js, python, csharp
- `data` <[string]|[Buffer]|[Serializable]>

Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string
and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` header will be
set to `application/octet-stream` if not explicitly set.

## js-python-fetch-option-ignorehttpserrors
## js-python-csharp-fetch-option-ignorehttpserrors
* langs: js, python, csharp
- `ignoreHTTPSErrors` <[boolean]>

Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.

## js-python-fetch-option-maxredirects
* langs: js
## js-python-csharp-fetch-option-maxredirects
* langs: js, python, csharp
- `maxRedirects` <[int]>

Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
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.

## evaluate-expression
- `expression` <[string]>
Expand Down
21 changes: 14 additions & 7 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12668,7 +12668,8 @@ export interface APIRequestContext {
ignoreHTTPSErrors?: boolean;

/**
* Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
* 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;

Expand Down Expand Up @@ -12753,7 +12754,8 @@ export interface APIRequestContext {
ignoreHTTPSErrors?: boolean;

/**
* Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
* 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;

Expand Down Expand Up @@ -12821,7 +12823,8 @@ export interface APIRequestContext {
ignoreHTTPSErrors?: boolean;

/**
* Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
* 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;

Expand Down Expand Up @@ -12860,7 +12863,8 @@ export interface APIRequestContext {
ignoreHTTPSErrors?: boolean;

/**
* Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
* 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;

Expand Down Expand Up @@ -12913,7 +12917,8 @@ export interface APIRequestContext {
ignoreHTTPSErrors?: boolean;

/**
* Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
* 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;

Expand Down Expand Up @@ -12989,7 +12994,8 @@ export interface APIRequestContext {
ignoreHTTPSErrors?: boolean;

/**
* Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
* 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;

Expand Down Expand Up @@ -13065,7 +13071,8 @@ export interface APIRequestContext {
ignoreHTTPSErrors?: boolean;

/**
* Maximum number of request allowed redirects. Defaults to `20`. Pass `0` to disable automatic follow.
* 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;

Expand Down
14 changes: 10 additions & 4 deletions tests/library/global-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,11 @@ it('should throw an error when maxRedirects is exceeded', async ({ playwright, s
server.setRedirect('/b/c/redirect4', '/simple.json');

const request = await playwright.request.newContext();
for (const method of ['GET', 'PUT', 'POST', 'OPTIONS', 'HEAD', 'PATCH'])
for (const maxRedirects of [1, 2, 3]) await expect(async () => request.fetch(`${server.PREFIX}/a/redirect1`, { method: method, maxRedirects: maxRedirects })).rejects.toThrow('Max redirect count exceeded');
for (const method of ['GET', 'PUT', 'POST', 'OPTIONS', 'HEAD', 'PATCH']) {
for (const maxRedirects of [1, 2, 3])
await expect(async () => request.fetch(`${server.PREFIX}/a/redirect1`, { method: method, maxRedirects: maxRedirects })).rejects.toThrow('Max redirect count exceeded');
}
await request.dispose();
});

it('should not follow redirects when maxRedirects is set to 0', async ({ playwright, server }) => {
Expand All @@ -401,16 +404,19 @@ it('should not follow redirects when maxRedirects is set to 0', async ({ playwri

const request = await playwright.request.newContext();
for (const method of ['GET', 'PUT', 'POST', 'OPTIONS', 'HEAD', 'PATCH']){
const response = await request.fetch(`${server.PREFIX}/a/redirect1`, { method: method, maxRedirects: 0 });
const response = await request.fetch(`${server.PREFIX}/a/redirect1`, { method, maxRedirects: 0 });
expect(response.headers()['location']).toBe('/b/c/redirect2');
expect(response.status()).toBe(302);
}
await request.dispose();
});

it('should throw an error when maxRedirects is less than 0', async ({ playwright, server }) => {
server.setRedirect('/a/redirect1', '/b/c/redirect2');
server.setRedirect('/b/c/redirect2', '/simple.json');

const request = await playwright.request.newContext();
for (const method of ['GET', 'PUT', 'POST', 'OPTIONS', 'HEAD', 'PATCH']) await expect(async () => request.fetch(`${server.PREFIX}/a/redirect1`, { method: method, maxRedirects: -1 })).rejects.toThrow(`'maxRedirects' should be greater than or equal to '0'`);
for (const method of ['GET', 'PUT', 'POST', 'OPTIONS', 'HEAD', 'PATCH'])
await expect(async () => request.fetch(`${server.PREFIX}/a/redirect1`, { method, maxRedirects: -1 })).rejects.toThrow(`'maxRedirects' should be greater than or equal to '0'`);
await request.dispose();
});

0 comments on commit 24ee456

Please sign in to comment.