Skip to content

Merge headers if passed via client_kwargs in query client #958

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

Merged
merged 2 commits into from
Mar 31, 2025

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Mar 26, 2025

No description provided.

@Kludex Kludex changed the title Merge headers if passed via client_kwargs Merge headers if passed via client_kwargs Mar 26, 2025
Copy link

cloudflare-workers-and-pages bot commented Mar 26, 2025

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: d16dba7
Status: ✅  Deploy successful!
Preview URL: https://18a17c22.logfire-docs.pages.dev
Branch Preview URL: https://please-merge-2.logfire-docs.pages.dev

View logs

@alexmojaki alexmojaki requested a review from Copilot March 26, 2025 17:26
Copy link
Contributor

@Copilot Copilot AI left a comment

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 ensures that headers passed via client_kwargs are merged with the default 'authorization' header in the query client. Key changes include:

  • Extracting headers from client_kwargs.
  • Merging the provided headers with the default authorization header.
  • Passing the updated headers to the client instance.

timeout=timeout, base_url=base_url, headers={'authorization': read_token}, **client_kwargs
)
headers = client_kwargs.pop('headers', {})
headers['authorization'] = read_token
Copy link
Preview

Copilot AI Mar 26, 2025

Choose a reason for hiding this comment

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

This line unconditionally sets the 'authorization' header, potentially overwriting an existing header provided via client_kwargs. Consider using headers.setdefault('authorization', read_token) or explicitly checking for an existing value to preserve any intended header overrides.

Suggested change
headers['authorization'] = read_token
headers.setdefault('authorization', read_token)

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't a terrible point. read_token should probably take priority but if there's a clash maybe we should emit a warning or something. but it doesn't actually matter.

self.client: T = client(
timeout=timeout, base_url=base_url, headers={'authorization': read_token}, **client_kwargs
)
headers = client_kwargs.pop('headers', {})
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd slightly prefer if headers was just a normal arg.

@alexmojaki alexmojaki enabled auto-merge (squash) March 31, 2025 10:31
@alexmojaki alexmojaki changed the title Merge headers if passed via client_kwargs Merge headers if passed via client_kwargs in query client Mar 31, 2025
@alexmojaki alexmojaki merged commit 2dd65cb into main Mar 31, 2025
14 checks passed
@alexmojaki alexmojaki deleted the please-merge-2 branch March 31, 2025 10:34
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.

2 participants