Skip to content

Conversation

cretz
Copy link
Member

@cretz cretz commented Mar 8, 2024

What was changed

  • Move headers from connect to the ClientOptions (💥 - intentional compatibility break)
  • Add api_key to ClientOptions and set_api_key on client to use as an "Authorization" bearer header if that header not already set

Checklist

  1. Closes [Feature Request] API key client option #695

@cretz cretz requested a review from a team as a code owner March 8, 2024 22:55
}

impl ClientHeaders {
fn apply_to_metadata(&self, metadata: &mut MetadataMap) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I considered doing some of this work on set rather than apply (md key/val creation, concat w/ "Bearer "), but it didn't seem too burdensome to do it on the call

Copy link
Member

Choose a reason for hiding this comment

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

This makes more sense to me anyway I think. Sure, it's "extra" work but totally irrelevant to performance and this is a bit more flexible

Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

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

Sweet, looks good to me. Thanks!

}

impl ClientHeaders {
fn apply_to_metadata(&self, metadata: &mut MetadataMap) {
Copy link
Member

Choose a reason for hiding this comment

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

This makes more sense to me anyway I think. Sure, it's "extra" work but totally irrelevant to performance and this is a bit more flexible

@cretz
Copy link
Member Author

cretz commented Mar 8, 2024

Just realized my build/test didn't catch all uses of the call, checking integ_tests and such and will push fixes...

Comment on lines 299 to 306
pub fn set_headers(&self, headers: HashMap<String, String>) {
let mut guard = self.headers.write();
*guard = headers;
self.headers.write().user_headers = headers;
}

/// Set API key, overwriting previous
pub fn set_api_key(&self, api_key: Option<String>) {
self.headers.write().api_key = api_key;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you keep consistent the headers in options.headers and the headers field in ConfiguredClient? Or are we assuming options are just the initial frozen options?

Copy link
Member Author

Choose a reason for hiding this comment

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

Options are just the initial frozen options as they always have been (but lang can make theirs mutable if they really want, which Python does but .NET doesn't)

Comment on lines 290 to +291
options: Arc<ClientOptions>,
headers: Arc<RwLock<HashMap<String, String>>>,
headers: Arc<RwLock<ClientHeaders>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm working on dynamic endpoints, updating the options field and reconnecting. Is the idea that update headers, that do not need reconnect, with always be updated with set_headers() and not by modifying options?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that idea has already been the case (set_headers has already existed, this just moves things around a bit). I think we need to differentiate things that don't require reconnect (i.e. HTTP headers) from things that do (i.e. hostname and TLS options).

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.

[Feature Request] API key client option

3 participants