Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set custom HTTP headers #453

Open
orian opened this issue Jan 10, 2025 · 2 comments
Open

Allow to set custom HTTP headers #453

orian opened this issue Jan 10, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@orian
Copy link
Contributor

orian commented Jan 10, 2025

Is your feature request related to a problem? Please describe.
We're proxying the queries and want to pass extra context for the proxy so it can make decisions where to send a query, how to rate limit it. We don't want to mess up with ClickHouse, therefore i'd prefer to not add extra GET parameters, therefore the idea is to add extra HTTP headers: X-Example-Customer-Id: 12

Describe the solution you'd like

headers = {'X-Example-Customer-Id': 12}
client.query(query=query, parameters=params, extra_http_headers=headers)

Describe alternatives you've considered

  1. Setup a full RPC service and have own protocol, but HTTP proxy seems like more bulletproof solution.
  2. Pass extra params as GET parameters and remove them when forwarding the query

This is a request for feedback, if you think it's a OK, i'm gonna implement it.

@orian orian added the enhancement New feature or request label Jan 10, 2025
@genzgd
Copy link
Collaborator

genzgd commented Jan 13, 2025

You can add headers to the client directly that will be used on every request, by using the client.header dictionary (and in theory you could add and remove them from the client after each request.

I'd rather not add yet more parameters to the query methods, but if that solution doesn't work for you (maybe a client per customer?) I'll consider a PR and put some thought into the cleanest way to allow easy manipulation per query.

@orian
Copy link
Contributor Author

orian commented Jan 14, 2025

We use a connection pool to manage clients, I've consider client-per-customer, it won't scale in our case. I'm gonna prepare a MR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants