mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(HTTP Request Node): avoid error when response doesn't include content-type (#4365)
* 🐛 Fix bug when response doesn't include content type * ⚡ Improve autodetect response format * ⚡ Make content-type match more specific * ⚡ Improve list of content-types to download
This commit is contained in:
@@ -12,7 +12,11 @@ import {
|
||||
|
||||
import { OptionsWithUri } from 'request-promise-native';
|
||||
|
||||
import { getOAuth2AdditionalParameters, replaceNullValues } from '../GenericFunctions';
|
||||
import {
|
||||
binaryContentTypes,
|
||||
getOAuth2AdditionalParameters,
|
||||
replaceNullValues,
|
||||
} from '../GenericFunctions';
|
||||
export class HttpRequestV3 implements INodeType {
|
||||
description: INodeTypeDescription;
|
||||
|
||||
@@ -1204,11 +1208,11 @@ export class HttpRequestV3 implements INodeType {
|
||||
) as boolean;
|
||||
|
||||
if (autoDetectResponseFormat) {
|
||||
const responseContentType = response.headers['content-type'];
|
||||
const responseContentType = response.headers['content-type'] ?? '';
|
||||
if (responseContentType.includes('application/json')) {
|
||||
responseFormat = 'json';
|
||||
response.body = JSON.parse(Buffer.from(response.body).toString());
|
||||
} else if (['image', 'audio', 'video'].some((e) => responseContentType.includes(e))) {
|
||||
} else if (binaryContentTypes.some((e) => responseContentType.includes(e))) {
|
||||
responseFormat = 'file';
|
||||
} else {
|
||||
responseFormat = 'text';
|
||||
|
||||
Reference in New Issue
Block a user