mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(Respond to Webhook Node): Return headers in response (#6921)
This commit is contained in:
parent
139e08a549
commit
a82107fb05
|
@ -113,7 +113,13 @@ export const webhookRequestHandler =
|
|||
|
||||
// Don't respond, if already responded
|
||||
if (response.noWebhookResponse !== true) {
|
||||
ResponseHelper.sendSuccessResponse(res, response.data, true, response.responseCode);
|
||||
ResponseHelper.sendSuccessResponse(
|
||||
res,
|
||||
response.data,
|
||||
true,
|
||||
response.responseCode,
|
||||
response.headers,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -56,20 +56,24 @@ describe('WebhookServer', () => {
|
|||
it('should handle regular requests', async () => {
|
||||
const pathPrefix = config.getEnv(`endpoints.${key}`);
|
||||
manager.getWebhookMethods.mockResolvedValueOnce(['GET']);
|
||||
manager.executeWebhook.mockResolvedValueOnce(mockResponse({ test: true }));
|
||||
manager.executeWebhook.mockResolvedValueOnce(
|
||||
mockResponse({ test: true }, { key: 'value ' }),
|
||||
);
|
||||
|
||||
const response = await agent.get(`/${pathPrefix}/abcd`).set('origin', corsOrigin);
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(response.body).toEqual({ test: true });
|
||||
expect(response.headers['access-control-allow-origin']).toEqual(corsOrigin);
|
||||
expect(response.headers.key).toEqual('value');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const mockResponse = (data = {}, status = 200) => {
|
||||
const mockResponse = (data = {}, headers = {}, status = 200) => {
|
||||
const response = mock<IResponseCallbackData>();
|
||||
response.responseCode = status;
|
||||
response.data = data;
|
||||
response.headers = headers;
|
||||
return response;
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue