mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-27 21:58:52 +03:00
feat(fetch): support ignoreHTTPSErrors option (#9206)
This commit is contained in:
parent
2b055b3092
commit
b93718daea
@ -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]>
|
||||
|
||||
@ -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]>
|
||||
|
||||
@ -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-%%
|
||||
|
@ -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 {
|
||||
@ -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,
|
||||
@ -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,
|
||||
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -174,6 +174,7 @@ export type FetchRequestFetchParams = {
|
||||
formData?: any,
|
||||
timeout?: number,
|
||||
failOnStatusCode?: boolean,
|
||||
ignoreHTTPSErrors?: boolean,
|
||||
};
|
||||
export type FetchRequestFetchOptions = {
|
||||
params?: NameValue[],
|
||||
@ -183,6 +184,7 @@ export type FetchRequestFetchOptions = {
|
||||
formData?: any,
|
||||
timeout?: number,
|
||||
failOnStatusCode?: boolean,
|
||||
ignoreHTTPSErrors?: boolean,
|
||||
};
|
||||
export type FetchRequestFetchResult = {
|
||||
response?: FetchResponse,
|
||||
|
@ -245,6 +245,7 @@ FetchRequest:
|
||||
formData: json?
|
||||
timeout: number?
|
||||
failOnStatusCode: boolean?
|
||||
ignoreHTTPSErrors: boolean?
|
||||
returns:
|
||||
response: FetchResponse?
|
||||
error: string?
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -393,6 +393,7 @@ export type FetchOptions = {
|
||||
formData?: FormField[],
|
||||
timeout?: number,
|
||||
failOnStatusCode?: boolean,
|
||||
ignoreHTTPSErrors?: boolean,
|
||||
};
|
||||
|
||||
export type FetchResponse = {
|
||||
|
@ -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 }) => {
|
||||
@ -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);
|
||||
|
15
types/types.d.ts
vendored
15
types/types.d.ts
vendored
@ -12701,6 +12701,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.
|
||||
*/
|
||||
@ -12734,6 +12739,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.
|
||||
*/
|
||||
@ -12772,6 +12782,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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user