surf icon indicating copy to clipboard operation
surf copied to clipboard

Consideration for returning `Request` type which is a bit complex right now

Open amanjeev opened this issue 5 years ago • 2 comments

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

  1. surf::http_client is not re-exported
  2. http_client::HttpClient complains its a different type and the impl does not exist. Rightly so because it has a different version of http-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

amanjeev avatar Mar 21 '20 20:03 amanjeev

If we can do https://github.com/http-rs/surf/issues/69, the type parameter will be removed entirely.

goto-bus-stop avatar Mar 22 '20 00:03 goto-bus-stop

Thank you @goto-bus-stop! Should we somehow mention this as a dependency on #69?

BTW: amazing github handle! :)

amanjeev avatar Mar 22 '20 17:03 amanjeev