mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-12 15:44:06 -08:00
fix(core): Ensure maxRedirects
is used for any http request defining it (#8706)
This commit is contained in:
parent
8c4a744c56
commit
246c988b93
|
@ -480,16 +480,14 @@ export async function parseRequestObject(requestObject: IRequestOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axios will follow redirects by default, so we simply tell it otherwise if needed.
|
// Axios will follow redirects by default, so we simply tell it otherwise if needed.
|
||||||
|
const { method } = requestObject;
|
||||||
if (
|
if (
|
||||||
requestObject.followRedirect === false &&
|
(requestObject.followRedirect !== false &&
|
||||||
((requestObject.method as string | undefined) || 'get').toLowerCase() === 'get'
|
(!method || method === 'GET' || method === 'HEAD')) ||
|
||||||
) {
|
requestObject.followAllRedirects
|
||||||
axiosConfig.maxRedirects = 0;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
requestObject.followAllRedirects === false &&
|
|
||||||
((requestObject.method as string | undefined) || 'get').toLowerCase() !== 'get'
|
|
||||||
) {
|
) {
|
||||||
|
axiosConfig.maxRedirects = requestObject.maxRedirects;
|
||||||
|
} else {
|
||||||
axiosConfig.maxRedirects = 0;
|
axiosConfig.maxRedirects = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import type { IncomingMessage } from 'http';
|
||||||
import { mock } from 'jest-mock-extended';
|
import { mock } from 'jest-mock-extended';
|
||||||
import type {
|
import type {
|
||||||
IBinaryData,
|
IBinaryData,
|
||||||
|
IHttpRequestMethods,
|
||||||
INode,
|
INode,
|
||||||
ITaskDataConnections,
|
ITaskDataConnections,
|
||||||
IWorkflowExecuteAdditionalData,
|
IWorkflowExecuteAdditionalData,
|
||||||
|
@ -368,6 +369,46 @@ describe('NodeExecuteFunctions', () => {
|
||||||
});
|
});
|
||||||
expect((axiosOptions.httpsAgent as Agent).options.servername).toEqual('example.de');
|
expect((axiosOptions.httpsAgent as Agent).options.servername).toEqual('example.de');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when followRedirect is true', () => {
|
||||||
|
test.each(['GET', 'HEAD'] as IHttpRequestMethods[])(
|
||||||
|
'should set maxRedirects on %s ',
|
||||||
|
async (method) => {
|
||||||
|
const axiosOptions = await parseRequestObject({
|
||||||
|
method,
|
||||||
|
followRedirect: true,
|
||||||
|
maxRedirects: 1234,
|
||||||
|
});
|
||||||
|
expect(axiosOptions.maxRedirects).toEqual(1234);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test.each(['POST', 'PUT', 'PATCH', 'DELETE'] as IHttpRequestMethods[])(
|
||||||
|
'should not set maxRedirects on %s ',
|
||||||
|
async (method) => {
|
||||||
|
const axiosOptions = await parseRequestObject({
|
||||||
|
method,
|
||||||
|
followRedirect: true,
|
||||||
|
maxRedirects: 1234,
|
||||||
|
});
|
||||||
|
expect(axiosOptions.maxRedirects).toEqual(0);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when followAllRedirects is true', () => {
|
||||||
|
test.each(['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'] as IHttpRequestMethods[])(
|
||||||
|
'should set maxRedirects on %s ',
|
||||||
|
async (method) => {
|
||||||
|
const axiosOptions = await parseRequestObject({
|
||||||
|
method,
|
||||||
|
followAllRedirects: true,
|
||||||
|
maxRedirects: 1234,
|
||||||
|
});
|
||||||
|
expect(axiosOptions.maxRedirects).toEqual(1234);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('copyInputItems', () => {
|
describe('copyInputItems', () => {
|
||||||
|
|
|
@ -325,14 +325,14 @@ export class HttpRequestV1 implements INodeType {
|
||||||
name: 'followAllRedirects',
|
name: 'followAllRedirects',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Whether to follow non-GET HTTP 3xx redirects',
|
description: 'Whether to follow All HTTP 3xx redirects',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Follow GET Redirect',
|
displayName: 'Follow GET/HEAD Redirect',
|
||||||
name: 'followRedirect',
|
name: 'followRedirect',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: true,
|
default: true,
|
||||||
description: 'Whether to follow GET HTTP 3xx redirects',
|
description: 'Whether to follow GET or HEAD HTTP 3xx redirects',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Ignore Response Code',
|
displayName: 'Ignore Response Code',
|
||||||
|
|
|
@ -340,14 +340,14 @@ export class HttpRequestV2 implements INodeType {
|
||||||
name: 'followAllRedirects',
|
name: 'followAllRedirects',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Whether to follow non-GET HTTP 3xx redirects',
|
description: 'Whether to follow All HTTP 3xx redirects',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Follow GET Redirect',
|
displayName: 'Follow GET/HEAD Redirect',
|
||||||
name: 'followRedirect',
|
name: 'followRedirect',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: true,
|
default: true,
|
||||||
description: 'Whether to follow GET HTTP 3xx redirects',
|
description: 'Whether to follow GET or HEAD HTTP 3xx redirects',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Ignore Response Code',
|
displayName: 'Ignore Response Code',
|
||||||
|
|
|
@ -552,15 +552,21 @@ export interface IRequestOptions {
|
||||||
json?: boolean;
|
json?: boolean;
|
||||||
useStream?: boolean;
|
useStream?: boolean;
|
||||||
encoding?: string | null;
|
encoding?: string | null;
|
||||||
followRedirect?: boolean;
|
|
||||||
followAllRedirects?: boolean;
|
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
rejectUnauthorized?: boolean;
|
rejectUnauthorized?: boolean;
|
||||||
proxy?: string | AxiosProxyConfig;
|
proxy?: string | AxiosProxyConfig;
|
||||||
simple?: boolean;
|
simple?: boolean;
|
||||||
gzip?: boolean;
|
gzip?: boolean;
|
||||||
maxRedirects?: number;
|
|
||||||
resolveWithFullResponse?: boolean;
|
resolveWithFullResponse?: boolean;
|
||||||
|
|
||||||
|
/** Whether to follow GET or HEAD HTTP 3xx redirects @default true */
|
||||||
|
followRedirect?: boolean;
|
||||||
|
|
||||||
|
/** Whether to follow **All** HTTP 3xx redirects @default false */
|
||||||
|
followAllRedirects?: boolean;
|
||||||
|
|
||||||
|
/** Max number of redirects to follow @default 21 */
|
||||||
|
maxRedirects?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PaginationOptions {
|
export interface PaginationOptions {
|
||||||
|
|
Loading…
Reference in a new issue