surf
surf copied to clipboard
Consideration for returning `Request` type which is a bit complex right now
Description
Returning Request type is a bit complex right now.
It takes a bit of work to figure out what to do to achieve this.
Why
Being able to return the Request is a common need.
Consider the example of a simple Proxy -
use surf::{Request as RequestAsClient, Response as ResponseAsClient};
use tide::{Request as RequestAsServer, Response as ResponseAsServer};
/// Receives request from client, returns corresponding request object
/// to the downstream server
pub fn map_request(
request_from_client: RequestAsServer<()>,
) -> RequestAsClient<http_client::isahc::IsahcClient> {
unimplemented!()
}
Issues
Does not work with any version other than Surf 2.0.0-alpha as
surf::http_clientis not re-exportedhttp_client::HttpClientcomplains its a different type and theimpldoes not exist. Rightly so because it has a different version ofhttp-client.
This works (compiles) only if RequestAsClient<http_client::isahc::IsahcClient> is provided by using Surf 2.0.0-alpha.
Even with 2.0.0-alpha, my assumption was to use RequestAsClient<http_client::HttpClient> but that throws error
|
8 | ) -> RequestAsClient<impl http_client::HttpClient> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expands to a recursive type
|
= note: type resolves to itself
Consideration
I am not sure what needs to be done but could returning Request be made a bit easier?
I am told that there is http-types in the works. Is that going to help eventually
align these?
cc @jbr
If we can do https://github.com/http-rs/surf/issues/69, the type parameter will be removed entirely.
Thank you @goto-bus-stop! Should we somehow mention this as a dependency on #69?
BTW: amazing github handle! :)