proxy: allow setting dynamic headers at intercept time#2881
Open
phlip9 wants to merge 1 commit intoseanmonstar:masterfrom
Open
proxy: allow setting dynamic headers at intercept time#2881phlip9 wants to merge 1 commit intoseanmonstar:masterfrom
phlip9 wants to merge 1 commit intoseanmonstar:masterfrom
Conversation
To support this, I need the callback in `Proxy::custom` to be able to return auth/headers alongside a `Url`. I've packaged the auth/headers as `ProxyExtra` (formerly `Extra`), which is now part of the public API. Preserving backwards compat needed some minor trait contortions. Technically there's a new `Sized` trait bound on `IntoProxy`, but this _should_ be OK, since I'm not sure how you would impl the trait for an unsized type anyway.
Owner
|
Thanks for the PR! I'm curious about your use case, would you need it to be something that runs with |
Author
|
Sure, you can see how we're using an older version here: https://github.com/lexe-app/lexe-public/blob/master/app-rs/src/client.rs#L300 The Before making a request, you call impl Client {
async fn node_info(&self) -> Result<NodeInfo, NodeApiError> {
self.ensure_authed().await?;
let run_url = &self.run_url;
let url = format!("{run_url}/app/node_info");
let req = self.run_rest.get(url, &Empty {});
self.run_rest.send(req).await
}
}A per-request proxy config might also work (as long as the connection pooling continues to work): impl Client {
async fn node_info(&self) -> Result<NodeInfo, NodeApiError> {
let url = format!("{run_url}/app/node_info");
let token = self.ensure_authed().await?;
let proxy = Proxy::all(self.gateway_url).custom_http_auth(token)?;
let req = self
.run_rest
.get(url, &Empty {})
.proxy(proxy);
self.run_rest.send(req).await
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My main use case here is to set a short-lived
Proxy-AuthorizationBearer auth token and dynamic trace id on a proxy connection.To support this, the callback in
Proxy::customneeds to be able to return auth/headers alongside aUrl.I've packaged the auth/headers as
ProxyExtra(formerlyExtra), which is now part of the public API.Preserving backwards compat needed some minor trait contortions. Technically there's a new
Sizedtrait bound onIntoProxy, but this should be OK, since I'm not sure how you would impl the trait for an unsized type anyway. Existing callers should not need to change anything.We've been running a (hacky) version of this patch for ~2 years. I just finally got around to cleaning this up so it's suitable for upstreaming : )