fix(core): Ensure maxRedirects is used for any http request defining it (#8706)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-02-22 17:56:48 +01:00 committed by GitHub
parent 8c4a744c56
commit 246c988b93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 62 additions and 17 deletions

View file

@ -480,16 +480,14 @@ export async function parseRequestObject(requestObject: IRequestOptions) {
}
// Axios will follow redirects by default, so we simply tell it otherwise if needed.
const { method } = requestObject;
if (
requestObject.followRedirect === false &&
((requestObject.method as string | undefined) || 'get').toLowerCase() === 'get'
) {
axiosConfig.maxRedirects = 0;
}
if (
requestObject.followAllRedirects === false &&
((requestObject.method as string | undefined) || 'get').toLowerCase() !== 'get'
(requestObject.followRedirect !== false &&
(!method || method === 'GET' || method === 'HEAD')) ||
requestObject.followAllRedirects
) {
axiosConfig.maxRedirects = requestObject.maxRedirects;
} else {
axiosConfig.maxRedirects = 0;
}

View file

@ -11,6 +11,7 @@ import type { IncomingMessage } from 'http';
import { mock } from 'jest-mock-extended';
import type {
IBinaryData,
IHttpRequestMethods,
INode,
ITaskDataConnections,
IWorkflowExecuteAdditionalData,
@ -368,6 +369,46 @@ describe('NodeExecuteFunctions', () => {
});
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', () => {

View file

@ -325,14 +325,14 @@ export class HttpRequestV1 implements INodeType {
name: 'followAllRedirects',
type: 'boolean',
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',
type: 'boolean',
default: true,
description: 'Whether to follow GET HTTP 3xx redirects',
description: 'Whether to follow GET or HEAD HTTP 3xx redirects',
},
{
displayName: 'Ignore Response Code',

View file

@ -340,14 +340,14 @@ export class HttpRequestV2 implements INodeType {
name: 'followAllRedirects',
type: 'boolean',
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',
type: 'boolean',
default: true,
description: 'Whether to follow GET HTTP 3xx redirects',
description: 'Whether to follow GET or HEAD HTTP 3xx redirects',
},
{
displayName: 'Ignore Response Code',

View file

@ -552,15 +552,21 @@ export interface IRequestOptions {
json?: boolean;
useStream?: boolean;
encoding?: string | null;
followRedirect?: boolean;
followAllRedirects?: boolean;
timeout?: number;
rejectUnauthorized?: boolean;
proxy?: string | AxiosProxyConfig;
simple?: boolean;
gzip?: boolean;
maxRedirects?: number;
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 {