Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/api/class-fetchrequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Request timeout in milliseconds.
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
for all status codes.

### option: FetchRequest.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%

## async method: FetchRequest.get
- returns: <[FetchResponse]>

Expand Down Expand Up @@ -89,6 +91,8 @@ Request timeout in milliseconds.
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
for all status codes.

### option: FetchRequest.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%

## async method: FetchRequest.post
- returns: <[FetchResponse]>

Expand Down Expand Up @@ -128,3 +132,5 @@ Request timeout in milliseconds.

Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
for all status codes.

### option: FetchRequest.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
4 changes: 4 additions & 0 deletions src/client/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type FetchOptions = {
data?: string | Buffer | Serializable,
timeout?: number,
failOnStatusCode?: boolean,
ignoreHTTPSErrors?: boolean,
};

export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, channels.FetchRequestInitializer> implements api.FetchRequest {
Expand All @@ -59,6 +60,7 @@ export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, cha
headers?: { [key: string]: string; };
timeout?: number;
failOnStatusCode?: boolean;
ignoreHTTPSErrors?: boolean,
}): Promise<FetchResponse> {
return this.fetch(urlOrRequest, {
...options,
Expand All @@ -74,6 +76,7 @@ export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, cha
data?: string | Buffer | Serializable;
timeout?: number;
failOnStatusCode?: boolean;
ignoreHTTPSErrors?: boolean,
}): Promise<FetchResponse> {
return this.fetch(urlOrRequest, {
...options,
Expand Down Expand Up @@ -129,6 +132,7 @@ export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, cha
formData,
timeout: options.timeout,
failOnStatusCode: options.failOnStatusCode,
ignoreHTTPSErrors: options.ignoreHTTPSErrors,
});
if (result.error)
throw new Error(result.error);
Expand Down
1 change: 1 addition & 0 deletions src/dispatchers/networkDispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class FetchRequestDispatcher extends Dispatcher<FetchRequest, channels.Fe
formData: params.formData,
timeout: params.timeout,
failOnStatusCode: params.failOnStatusCode,
ignoreHTTPSErrors: params.ignoreHTTPSErrors,
});
let response;
if (fetchResponse) {
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export type FetchRequestFetchParams = {
formData?: any,
timeout?: number,
failOnStatusCode?: boolean,
ignoreHTTPSErrors?: boolean,
};
export type FetchRequestFetchOptions = {
params?: NameValue[],
Expand All @@ -183,6 +184,7 @@ export type FetchRequestFetchOptions = {
formData?: any,
timeout?: number,
failOnStatusCode?: boolean,
ignoreHTTPSErrors?: boolean,
};
export type FetchRequestFetchResult = {
response?: FetchResponse,
Expand Down
1 change: 1 addition & 0 deletions src/protocol/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ FetchRequest:
formData: json?
timeout: number?
failOnStatusCode: boolean?
ignoreHTTPSErrors: boolean?
returns:
response: FetchResponse?
error: string?
Expand Down
1 change: 1 addition & 0 deletions src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
formData: tOptional(tAny),
timeout: tOptional(tNumber),
failOnStatusCode: tOptional(tBoolean),
ignoreHTTPSErrors: tOptional(tBoolean),
});
scheme.FetchRequestFetchResponseBodyParams = tObject({
fetchUid: tString,
Expand Down
2 changes: 1 addition & 1 deletion src/server/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export abstract class FetchRequest extends SdkObject {
deadline
};
// rejectUnauthorized = undefined is treated as true in node 12.
if (defaults.ignoreHTTPSErrors)
if (params.ignoreHTTPSErrors || defaults.ignoreHTTPSErrors)
options.rejectUnauthorized = false;

const requestUrl = new URL(params.url, defaults.baseURL);
Expand Down
1 change: 1 addition & 0 deletions src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ export type FetchOptions = {
formData?: FormField[],
timeout?: number,
failOnStatusCode?: boolean,
ignoreHTTPSErrors?: boolean,
};

export type FetchResponse = {
Expand Down
7 changes: 6 additions & 1 deletion tests/browsercontext-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ for (const method of ['get', 'post', 'fetch']) {
}).catch(e => e);
expect(error.message).toContain('404 Not Found');
});

it(`${method}should support ignoreHTTPSErrors option`, async ({ context, httpsServer }) => {
const response = await context._request[method](httpsServer.EMPTY_PAGE, { ignoreHTTPSErrors: true });
expect(response.status()).toBe(200);
});
}

it('should not add context cookie if cookie header passed as a parameter', async ({ context, server }) => {
Expand Down Expand Up @@ -517,7 +522,7 @@ it('should support https', async ({ context, httpsServer }) => {
}
});

it('should support ignoreHTTPSErrors', async ({ contextFactory, contextOptions, httpsServer }) => {
it('should inherit ignoreHTTPSErrors from context', async ({ contextFactory, contextOptions, httpsServer }) => {
const context = await contextFactory({ ...contextOptions, ignoreHTTPSErrors: true });
const response = await context._request.get(httpsServer.EMPTY_PAGE);
expect(response.status()).toBe(200);
Expand Down
15 changes: 15 additions & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12667,6 +12667,11 @@ export interface FetchRequest {
*/
headers?: { [key: string]: string; };

/**
* Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
*/
ignoreHTTPSErrors?: boolean;

/**
* If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.
*/
Expand Down Expand Up @@ -12700,6 +12705,11 @@ export interface FetchRequest {
*/
headers?: { [key: string]: string; };

/**
* Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
*/
ignoreHTTPSErrors?: boolean;

/**
* Query parameters to be send with the URL.
*/
Expand Down Expand Up @@ -12738,6 +12748,11 @@ export interface FetchRequest {
*/
headers?: { [key: string]: string; };

/**
* Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.
*/
ignoreHTTPSErrors?: boolean;

/**
* Query parameters to be send with the URL.
*/
Expand Down