fix: Send custom headers on every request, not just the initial POST#97
fix: Send custom headers on every request, not just the initial POST#97ovr wants to merge 1 commit into
Conversation
The `headers` option passed to `execute()` was only applied to the initial `POST /v1/statement` request. The follow-up `nextUri` GET polls (and the cancel/info requests) rebuild a fresh, empty header set, so any custom headers were dropped after the first request. This breaks setups where a proxy/gateway in front of Presto/Trino authenticates every request (e.g. via `Proxy-Authorization`), failing with "User authentication failed" once polling starts. Thread the per-execute `headers` through `request` the same way the `authorization` option is already threaded, and re-apply them on every request (before the client-managed `X-Presto-/X-Trino-*` headers so the protocol headers still take precedence).
There was a problem hiding this comment.
Pull request overview
This PR fixes execute({ headers }) so caller-provided custom headers are included not only on the initial POST /v1/statement, but also on subsequent nextUri polling requests (and related follow-up requests), which is important for proxy/gateway setups that require headers on every request.
Changes:
- Thread per-
execute()custom headers through the internalrequest()path and re-apply them to follow-up requests. - Update README documentation and changelog note to reflect the new “headers on every request” behavior.
- Add a regression test asserting custom headers are present on the initial POST and
nextUripolling GET.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| README.md | Documents that execute({ headers }) applies to all requests in a query lifecycle and adds an Unreleased changelog entry. |
| lib/presto-client/index.js | Adds an extraHeaders parameter to request() and passes it through statement polling/cancel/info calls. |
| index.spec.js | Adds a regression test for forwarding custom headers to nextUri polling requests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (extraHeaders) { | ||
| for (var headerName in extraHeaders) { | ||
| opts.headers[headerName] = extraHeaders[headerName]; | ||
| } | ||
| } |
| test('forwards custom headers on every request, including nextUri polls', function(done){ | ||
| expect.assertions(6); | ||
| var client = new Client({ | ||
| host: 'localhost', | ||
| port: 8111, | ||
| }); | ||
| client.execute({ | ||
| query: 'SELECT 1 AS col', | ||
| headers: { | ||
| 'X-Custom-Header': 'custom-value', | ||
| 'Proxy-Authorization': 'Basic dGVzdA==', | ||
| }, | ||
| callback: function(error){ | ||
| expect(error).toBeNull(); | ||
|
|
||
| var post = received.find(function(r){ return r.method === 'POST'; }); | ||
| var poll = received.find(function(r){ return r.method === 'GET'; }); | ||
|
|
||
| // Custom headers have always been sent on the initial POST. | ||
| expect(post.headers['x-custom-header']).toBe('custom-value'); | ||
| expect(post.headers['proxy-authorization']).toBe('Basic dGVzdA=='); | ||
|
|
||
| // The nextUri poll must carry them too — this is what regressed. | ||
| expect(poll).toBeDefined(); | ||
| expect(poll.headers['x-custom-header']).toBe('custom-value'); | ||
| expect(poll.headers['proxy-authorization']).toBe('Basic dGVzdA=='); | ||
|
|
|
|
||
| if (extraHeaders) { | ||
| for (var headerName in extraHeaders) { | ||
| opts.headers[headerName] = extraHeaders[headerName]; |
There was a problem hiding this comment.
This code changes the given opts.headers, and it's unsafe if the argument opts is re-used in several different places.
Could you change this code to copy opts.headers and then assign the pairs of extraHeaders?
The
headersoption passed toexecute()was only applied to the initialPOST /v1/statementrequest. The follow-upnextUriGET polls (and the cancel/info requests) rebuild a fresh, empty header set, so any custom headers were dropped after the first request. This breaks setups where a proxy/gateway in front of Presto/Trino authenticates every request (e.g. viaProxy-Authorization), failing with "User authentication failed" once polling starts.Thread the per-execute
headersthroughrequestthe same way theauthorizationoption is already threaded, and re-apply them on every request (before the client-managedX-Presto-/X-Trino-*headers so the protocol headers still take precedence).