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
|
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
|
||||||
for all status codes.
|
for all status codes.
|
||||||
|
|
||||||
|
### option: FetchRequest.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||||
|
|
||||||
## async method: FetchRequest.get
|
## async method: FetchRequest.get
|
||||||
- returns: <[FetchResponse]>
|
- 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
|
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
|
||||||
for all status codes.
|
for all status codes.
|
||||||
|
|
||||||
|
### option: FetchRequest.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||||
|
|
||||||
## async method: FetchRequest.post
|
## async method: FetchRequest.post
|
||||||
- returns: <[FetchResponse]>
|
- 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
|
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
|
||||||
for all status codes.
|
for all status codes.
|
||||||
|
|
||||||
|
### option: FetchRequest.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ export type FetchOptions = {
|
||||||
data?: string | Buffer | Serializable,
|
data?: string | Buffer | Serializable,
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
failOnStatusCode?: boolean,
|
failOnStatusCode?: boolean,
|
||||||
|
ignoreHTTPSErrors?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, channels.FetchRequestInitializer> implements api.FetchRequest {
|
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; };
|
headers?: { [key: string]: string; };
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
failOnStatusCode?: boolean;
|
failOnStatusCode?: boolean;
|
||||||
|
ignoreHTTPSErrors?: boolean,
|
||||||
}): Promise<FetchResponse> {
|
}): Promise<FetchResponse> {
|
||||||
return this.fetch(urlOrRequest, {
|
return this.fetch(urlOrRequest, {
|
||||||
...options,
|
...options,
|
||||||
|
|
@ -74,6 +76,7 @@ export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, cha
|
||||||
data?: string | Buffer | Serializable;
|
data?: string | Buffer | Serializable;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
failOnStatusCode?: boolean;
|
failOnStatusCode?: boolean;
|
||||||
|
ignoreHTTPSErrors?: boolean,
|
||||||
}): Promise<FetchResponse> {
|
}): Promise<FetchResponse> {
|
||||||
return this.fetch(urlOrRequest, {
|
return this.fetch(urlOrRequest, {
|
||||||
...options,
|
...options,
|
||||||
|
|
@ -129,6 +132,7 @@ export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, cha
|
||||||
formData,
|
formData,
|
||||||
timeout: options.timeout,
|
timeout: options.timeout,
|
||||||
failOnStatusCode: options.failOnStatusCode,
|
failOnStatusCode: options.failOnStatusCode,
|
||||||
|
ignoreHTTPSErrors: options.ignoreHTTPSErrors,
|
||||||
});
|
});
|
||||||
if (result.error)
|
if (result.error)
|
||||||
throw new Error(result.error);
|
throw new Error(result.error);
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ export class FetchRequestDispatcher extends Dispatcher<FetchRequest, channels.Fe
|
||||||
formData: params.formData,
|
formData: params.formData,
|
||||||
timeout: params.timeout,
|
timeout: params.timeout,
|
||||||
failOnStatusCode: params.failOnStatusCode,
|
failOnStatusCode: params.failOnStatusCode,
|
||||||
|
ignoreHTTPSErrors: params.ignoreHTTPSErrors,
|
||||||
});
|
});
|
||||||
let response;
|
let response;
|
||||||
if (fetchResponse) {
|
if (fetchResponse) {
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ export type FetchRequestFetchParams = {
|
||||||
formData?: any,
|
formData?: any,
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
failOnStatusCode?: boolean,
|
failOnStatusCode?: boolean,
|
||||||
|
ignoreHTTPSErrors?: boolean,
|
||||||
};
|
};
|
||||||
export type FetchRequestFetchOptions = {
|
export type FetchRequestFetchOptions = {
|
||||||
params?: NameValue[],
|
params?: NameValue[],
|
||||||
|
|
@ -183,6 +184,7 @@ export type FetchRequestFetchOptions = {
|
||||||
formData?: any,
|
formData?: any,
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
failOnStatusCode?: boolean,
|
failOnStatusCode?: boolean,
|
||||||
|
ignoreHTTPSErrors?: boolean,
|
||||||
};
|
};
|
||||||
export type FetchRequestFetchResult = {
|
export type FetchRequestFetchResult = {
|
||||||
response?: FetchResponse,
|
response?: FetchResponse,
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,7 @@ FetchRequest:
|
||||||
formData: json?
|
formData: json?
|
||||||
timeout: number?
|
timeout: number?
|
||||||
failOnStatusCode: boolean?
|
failOnStatusCode: boolean?
|
||||||
|
ignoreHTTPSErrors: boolean?
|
||||||
returns:
|
returns:
|
||||||
response: FetchResponse?
|
response: FetchResponse?
|
||||||
error: string?
|
error: string?
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||||
formData: tOptional(tAny),
|
formData: tOptional(tAny),
|
||||||
timeout: tOptional(tNumber),
|
timeout: tOptional(tNumber),
|
||||||
failOnStatusCode: tOptional(tBoolean),
|
failOnStatusCode: tOptional(tBoolean),
|
||||||
|
ignoreHTTPSErrors: tOptional(tBoolean),
|
||||||
});
|
});
|
||||||
scheme.FetchRequestFetchResponseBodyParams = tObject({
|
scheme.FetchRequestFetchResponseBodyParams = tObject({
|
||||||
fetchUid: tString,
|
fetchUid: tString,
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ export abstract class FetchRequest extends SdkObject {
|
||||||
deadline
|
deadline
|
||||||
};
|
};
|
||||||
// rejectUnauthorized = undefined is treated as true in node 12.
|
// rejectUnauthorized = undefined is treated as true in node 12.
|
||||||
if (defaults.ignoreHTTPSErrors)
|
if (params.ignoreHTTPSErrors || defaults.ignoreHTTPSErrors)
|
||||||
options.rejectUnauthorized = false;
|
options.rejectUnauthorized = false;
|
||||||
|
|
||||||
const requestUrl = new URL(params.url, defaults.baseURL);
|
const requestUrl = new URL(params.url, defaults.baseURL);
|
||||||
|
|
|
||||||
|
|
@ -393,6 +393,7 @@ export type FetchOptions = {
|
||||||
formData?: FormField[],
|
formData?: FormField[],
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
failOnStatusCode?: boolean,
|
failOnStatusCode?: boolean,
|
||||||
|
ignoreHTTPSErrors?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FetchResponse = {
|
export type FetchResponse = {
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,11 @@ for (const method of ['get', 'post', 'fetch']) {
|
||||||
}).catch(e => e);
|
}).catch(e => e);
|
||||||
expect(error.message).toContain('404 Not Found');
|
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 }) => {
|
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 context = await contextFactory({ ...contextOptions, ignoreHTTPSErrors: true });
|
||||||
const response = await context._request.get(httpsServer.EMPTY_PAGE);
|
const response = await context._request.get(httpsServer.EMPTY_PAGE);
|
||||||
expect(response.status()).toBe(200);
|
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; };
|
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.
|
* 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; };
|
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.
|
* Query parameters to be send with the URL.
|
||||||
*/
|
*/
|
||||||
|
|
@ -12772,6 +12782,11 @@ export interface FetchRequest {
|
||||||
*/
|
*/
|
||||||
headers?: { [key: string]: string; };
|
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.
|
* Query parameters to be send with the URL.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue