-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add option to select HTTP client type #1079
base: main
Are you sure you want to change the base?
Conversation
Currently `reqwest::Client` is the only type we allow as the underlying HTTP client. Some consumers of Progenitor may want to use `reqwest_middleware` to enable conveniences like automatic retries and support for `tracing`. Add a new `with_client_type` argument for `GenerationSettings` to allow callers to select which of these types to use as the client.
Reqwest added the `from_parts` and `build_split` methods on `RequestBuilder` for wasm targets with v0.12.5. Bump Reqwest on the wasm example to that version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are significant obstacles to consider. For example, I don't think reqwest-middleware should become a dependency in omicron.
I would suggest we consider other approaches to allow for more inspection of CLI requests.
@@ -244,6 +265,7 @@ pub fn dependencies(builder: Generator, include_client: bool) -> Vec<String> { | |||
format!("bytes = \"{}\"", DEPENDENCIES.bytes), | |||
format!("futures-core = \"{}\"", DEPENDENCIES.futures), | |||
format!("reqwest = {{ version = \"{}\", default-features=false, features = [\"json\", \"stream\"] }}", DEPENDENCIES.reqwest), | |||
format!("reqwest-middleware = {{ version = \"{}\", default-features=false, features = [\"json\"] }}", DEPENDENCIES.reqwest_middleware), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to always include this dependency.
bytes = { workspace = true } | ||
futures-core = { workspace = true } | ||
percent-encoding = { workspace = true } | ||
reqwest = { workspace = true } | ||
reqwest-middleware = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be a mandatory dependency
@@ -7,10 +7,12 @@ repository = "https://github.com/oxidecomputer/progenitor.git" | |||
description = "An OpenAPI client generator - client support" | |||
|
|||
[dependencies] | |||
anyhow = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a step in the wrong direction. If we need a generic error, could we use Box?
impl Default for ClientType { | ||
fn default() -> Self { | ||
Self::Reqwest | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you could derive default on enums and use a marker annotation
ClientType::Reqwest => quote! { reqwest::Client }, | ||
ClientType::ReqwestMiddleware => quote! { reqwest_middleware::ClientWithMiddleware }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClientType::Reqwest => quote! { reqwest::Client }, | |
ClientType::ReqwestMiddleware => quote! { reqwest_middleware::ClientWithMiddleware }, | |
ClientType::Reqwest => quote! { ::reqwest::Client }, | |
ClientType::ReqwestMiddleware => quote! { ::reqwest_middleware::ClientWithMiddleware }, |
@@ -31,6 +31,7 @@ http = { workspace = true } | |||
hyper = { workspace = true } | |||
progenitor-client = { workspace = true } | |||
reqwest = { workspace = true } | |||
reqwest-middleware = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what fails if this is not present?
Currently
reqwest::Client
is the only type we allow as the underlying HTTP client. Some consumers of Progenitor may want to usereqwest_middleware
to enable conveniences like automatic retries and support fortracing
.Add a new
with_client_type
argument forGenerationSettings
to allow callers to select which of these types to use as the client.