fix(HTTP Request Node): Tolerate header name being empty (#9138)

This commit is contained in:
Elias Meire
2024-04-17 09:45:38 +02:00
committed by GitHub
parent 4c16000efa
commit f6c9dbf7b8
3 changed files with 184 additions and 131 deletions

View File

@@ -1527,7 +1527,10 @@ export class HttpRequestV3 implements INodeType {
if (sendHeaders && headerParameters) { if (sendHeaders && headerParameters) {
let additionalHeaders: IDataObject = {}; let additionalHeaders: IDataObject = {};
if (specifyHeaders === 'keypair') { if (specifyHeaders === 'keypair') {
additionalHeaders = await reduceAsync(headerParameters, parametersToKeyValue); additionalHeaders = await reduceAsync(
headerParameters.filter((header) => header.name),
parametersToKeyValue,
);
} else if (specifyHeaders === 'json') { } else if (specifyHeaders === 'json') {
// body is specified using JSON // body is specified using JSON
try { try {

View File

@@ -59,6 +59,12 @@ describe('Test HTTP Request Node', () => {
completed: true, completed: true,
userId: 26, userId: 26,
}); });
nock(baseUrl).get('/todos/1').reply(200, {
id: 1,
todo: 'Do something nice for someone I care about',
completed: true,
userId: 26,
});
nock(baseUrl).matchHeader('Authorization', 'Bearer 12345').get('/todos/3').reply(200, { nock(baseUrl).matchHeader('Authorization', 'Bearer 12345').get('/todos/3').reply(200, {
id: 3, id: 3,
todo: 'Watch a classic movie', todo: 'Watch a classic movie',

View File

@@ -1,144 +1,188 @@
{ {
"name": "http request test", "name": "HTTP Request test",
"nodes": [ "nodes": [
{ {
"parameters": {}, "parameters": {},
"id": "12433cfb-74d9-4bf1-9afd-0ab9afc9ef19", "id": "3db51d12-a71b-4d0d-84db-1d4c46454c40",
"name": "When clicking \"Execute Workflow\"", "name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger", "type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1, "typeVersion": 1,
"position": [820, 360] "position": [
160,
720
]
},
{
"parameters": {
"url": "https://dummyjson.com/todos/1",
"options": {}
}, },
{ "id": "96f38d87-0bdd-420c-b981-26fd55d11cb2",
"parameters": { "name": "HTTP Request",
"url": "https://dummyjson.com/todos/1", "type": "n8n-nodes-base.httpRequest",
"options": {} "typeVersion": 3,
}, "position": [
"id": "07670093-862f-403f-96a5-ddf7fdb0d225", 460,
"name": "HTTP Request", 460
"type": "n8n-nodes-base.httpRequest", ]
"typeVersion": 3, },
"position": [1120, 100] {
"parameters": {
"url": "https://dummyjson.com/todos/3",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer 12345"
}
]
},
"options": {}
}, },
{ "id": "85ca0a5b-3ff4-491d-ba51-990fdf2b757f",
"parameters": { "name": "HTTP Request fake header",
"url": "https://dummyjson.com/todos/3", "type": "n8n-nodes-base.httpRequest",
"sendHeaders": true, "typeVersion": 3,
"headerParameters": { "position": [
"parameters": [ 460,
{ 800
"name": "Authorization", ]
"value": "Bearer 12345" },
} {
] "parameters": {
}, "url": "https://dummyjson.com/todos",
"options": {} "sendQuery": true,
}, "queryParameters": {
"id": "25cc4f31-9363-4247-a49d-7ac49f174d16", "parameters": [
"name": "HTTP Request fake header", {
"type": "n8n-nodes-base.httpRequest", "name": "limit",
"typeVersion": 3, "value": "2"
"position": [1120, 440] },
{
"name": "skip",
"value": "10"
}
]
},
"options": {}
}, },
{ "id": "68d6e51a-66ea-45bf-928c-55efd2493cf0",
"parameters": { "name": "HTTP Request with query",
"url": "https://dummyjson.com/todos", "type": "n8n-nodes-base.httpRequest",
"sendQuery": true, "typeVersion": 3,
"queryParameters": { "position": [
"parameters": [ 460,
{ 980
"name": "limit", ]
"value": "2" },
}, {
{ "parameters": {
"name": "skip", "url": "https://dummyjson.com/todos/1",
"value": "10" "sendHeaders": true,
} "options": {}
] },
}, "id": "38ec1a50-7f0e-4749-822d-f26370b00694",
"options": {} "name": "HTTP Request empty header",
}, "type": "n8n-nodes-base.httpRequest",
"id": "33c80933-b113-4eff-beb7-4a5b0bc30bcf", "typeVersion": 3,
"name": "HTTP Request with query", "position": [
"type": "n8n-nodes-base.httpRequest", 460,
"typeVersion": 3, 640
"position": [1120, 620] ]
} }
], ],
"pinData": { "pinData": {
"HTTP Request": [ "HTTP Request": [
{ {
"json": { "json": {
"id": 1, "id": 1,
"todo": "Do something nice for someone I care about", "todo": "Do something nice for someone I care about",
"completed": true, "completed": true,
"userId": 26 "userId": 26
} }
} }
], ],
"HTTP Request with query": [ "HTTP Request with query": [
{ {
"json": { "json": {
"todos": [ "todos": [
{ {
"id": 11, "id": 11,
"todo": "Text a friend I haven't talked to in a long time", "todo": "Text a friend I haven't talked to in a long time",
"completed": false, "completed": false,
"userId": 39 "userId": 39
}, },
{ {
"id": 12, "id": 12,
"todo": "Organize pantry", "todo": "Organize pantry",
"completed": true, "completed": true,
"userId": 39 "userId": 39
} }
], ],
"total": 150, "total": 150,
"skip": 10, "skip": 10,
"limit": 2 "limit": 2
} }
} }
], ],
"HTTP Request fake header": [ "HTTP Request fake header": [
{ {
"json": { "json": {
"id": 3, "id": 3,
"todo": "Watch a classic movie", "todo": "Watch a classic movie",
"completed": false, "completed": false,
"userId": 4 "userId": 4
} }
} }
] ],
"HTTP Request empty header": [
{
"json": {
"id": 1,
"todo": "Do something nice for someone I care about",
"completed": true,
"userId": 26
}
}
]
}, },
"connections": { "connections": {
"When clicking \"Execute Workflow\"": { "When clicking \"Execute Workflow\"": {
"main": [ "main": [
[ [
{ {
"node": "HTTP Request", "node": "HTTP Request",
"type": "main", "type": "main",
"index": 0 "index": 0
}, },
{ {
"node": "HTTP Request with query", "node": "HTTP Request with query",
"type": "main", "type": "main",
"index": 0 "index": 0
}, },
{ {
"node": "HTTP Request fake header", "node": "HTTP Request fake header",
"type": "main", "type": "main",
"index": 0 "index": 0
} },
] {
] "node": "HTTP Request empty header",
} "type": "main",
"index": 0
}
]
]
}
}, },
"active": false, "active": false,
"settings": {}, "settings": {
"versionId": "0fb64565-22b3-4ff3-8ba4-354b2bcaf8a6", "executionOrder": "v1"
"id": "108", },
"versionId": "",
"meta": { "meta": {
"instanceId": "36203ea1ce3cef713fa25999bd9874ae26b9e4c2c3a90a365f2882a154d031d0" "templateCredsSetupCompleted": true,
"instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4"
}, },
"tags": [] "tags": []
} }