-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(HTTP Request Node): Respect the original encoding of the incoming…
… response (#9869)
- Loading branch information
Showing
9 changed files
with
152 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
import { Readable } from 'node:stream'; | ||
import { createGunzip } from 'node:zlib'; | ||
import { toBuffer } from '@/BinaryData/utils'; | ||
import { binaryToBuffer } from '@/BinaryData/utils'; | ||
|
||
describe('BinaryData/utils', () => { | ||
describe('toBuffer', () => { | ||
describe('binaryToBuffer', () => { | ||
it('should handle buffer objects', async () => { | ||
const body = Buffer.from('test'); | ||
expect((await toBuffer(body)).toString()).toEqual('test'); | ||
expect((await binaryToBuffer(body)).toString()).toEqual('test'); | ||
}); | ||
|
||
it('should handle valid uncompressed Readable streams', async () => { | ||
const body = Readable.from(Buffer.from('test')); | ||
expect((await toBuffer(body)).toString()).toEqual('test'); | ||
expect((await binaryToBuffer(body)).toString()).toEqual('test'); | ||
}); | ||
|
||
it('should handle valid compressed Readable streams', async () => { | ||
const gunzip = createGunzip(); | ||
const body = Readable.from( | ||
Buffer.from('1f8b08000000000000032b492d2e01000c7e7fd804000000', 'hex'), | ||
).pipe(gunzip); | ||
expect((await toBuffer(body)).toString()).toEqual('test'); | ||
expect((await binaryToBuffer(body)).toString()).toEqual('test'); | ||
}); | ||
|
||
it('should throw on invalid compressed Readable streams', async () => { | ||
const gunzip = createGunzip(); | ||
const body = Readable.from(Buffer.from('0001f8b080000000000000000', 'hex')).pipe(gunzip); | ||
await expect(toBuffer(body)).rejects.toThrow(new Error('Failed to decompress response')); | ||
await expect(binaryToBuffer(body)).rejects.toThrow( | ||
new Error('Failed to decompress response'), | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/nodes-base/nodes/HttpRequest/test/encoding/HttpRequest.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import nock from 'nock'; | ||
import { | ||
setup, | ||
equalityTest, | ||
workflowToTests, | ||
getWorkflowFilenames, | ||
initBinaryDataService, | ||
} from '@test/nodes/Helpers'; | ||
|
||
describe('Test Response Encoding', () => { | ||
const workflows = getWorkflowFilenames(__dirname); | ||
const tests = workflowToTests(workflows); | ||
|
||
const baseUrl = 'https://dummy.domain'; | ||
const payload = Buffer.from( | ||
'El rápido zorro marrón salta sobre el perro perezoso. ¡Qué bello día en París! Árbol, cañón, façade.', | ||
'latin1', | ||
); | ||
|
||
beforeAll(async () => { | ||
await initBinaryDataService(); | ||
|
||
nock.disableNetConnect(); | ||
|
||
nock(baseUrl) | ||
.persist() | ||
.get('/index.html') | ||
.reply(200, payload, { 'content-type': 'text/plain; charset=latin1' }); | ||
}); | ||
|
||
afterAll(() => { | ||
nock.restore(); | ||
}); | ||
|
||
const nodeTypes = setup(tests); | ||
|
||
for (const testData of tests) { | ||
test(testData.description, async () => await equalityTest(testData, nodeTypes)); | ||
} | ||
}); |
78 changes: 78 additions & 0 deletions
78
packages/nodes-base/nodes/HttpRequest/test/encoding/encoding.test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"name": "Response Encoding Test", | ||
"nodes": [ | ||
{ | ||
"parameters": {}, | ||
"name": "When clicking \"Execute Workflow\"", | ||
"type": "n8n-nodes-base.manualTrigger", | ||
"typeVersion": 1, | ||
"position": [ | ||
180, | ||
820 | ||
], | ||
"id": "635fb102-a760-4b9e-836c-82e71bba7974" | ||
}, | ||
{ | ||
"parameters": { | ||
"url": "https://dummy.domain/index.html", | ||
"options": {} | ||
}, | ||
"name": "HTTP Request (v3)", | ||
"type": "n8n-nodes-base.httpRequest", | ||
"typeVersion": 3, | ||
"position": [ | ||
520, | ||
720 | ||
], | ||
"id": "eb243cfd-fbd6-41ef-935d-4ea98617355f" | ||
}, | ||
{ | ||
"parameters": { | ||
"url": "https://dummy.domain/index.html", | ||
"options": {} | ||
}, | ||
"name": "HTTP Request (v4)", | ||
"type": "n8n-nodes-base.httpRequest", | ||
"typeVersion": 4, | ||
"position": [ | ||
520, | ||
920 | ||
], | ||
"id": "cc2f185d-df6a-4fa3-b7f4-29f0dbad0f9b" | ||
} | ||
], | ||
"connections": { | ||
"When clicking \"Execute Workflow\"": { | ||
"main": [ | ||
[ | ||
{ | ||
"node": "HTTP Request (v3)", | ||
"type": "main", | ||
"index": 0 | ||
}, | ||
{ | ||
"node": "HTTP Request (v4)", | ||
"type": "main", | ||
"index": 0 | ||
} | ||
] | ||
] | ||
} | ||
}, | ||
"pinData": { | ||
"HTTP Request (v3)": [ | ||
{ | ||
"json": { | ||
"data": "El rápido zorro marrón salta sobre el perro perezoso. ¡Qué bello día en París! Árbol, cañón, façade." | ||
} | ||
} | ||
], | ||
"HTTP Request (v4)": [ | ||
{ | ||
"json": { | ||
"data": "El rápido zorro marrón salta sobre el perro perezoso. ¡Qué bello día en París! Árbol, cañón, façade." | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters