Skip to content

fix: Send custom headers on every request, not just the initial POST#97

Open
ovr wants to merge 1 commit into
tagomoris:masterfrom
ovr:fix/custom-headers-on-all-requests
Open

fix: Send custom headers on every request, not just the initial POST#97
ovr wants to merge 1 commit into
tagomoris:masterfrom
ovr:fix/custom-headers-on-all-requests

Conversation

@ovr

@ovr ovr commented Jun 8, 2026

Copy link
Copy Markdown

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).

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).
@ovr ovr changed the title feat: Send custom headers on every request, not just the initial POST fix: Send custom headers on every request, not just the initial POST Jun 8, 2026
@tagomoris tagomoris requested a review from Copilot June 17, 2026 00:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 internal request() 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 nextUri polling 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.

Comment on lines +97 to +101
if (extraHeaders) {
for (var headerName in extraHeaders) {
opts.headers[headerName] = extraHeaders[headerName];
}
}
Comment thread index.spec.js
Comment on lines +539 to +565
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];

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants