Open pwoolcoc opened 4 years ago
I just ran into this issue as well.
In fact, none of the headers are copied from the http_types::Request
. I'm also not seeing a body from a Vec<u8>
being copied either.
Content-Type
is only getting set as a result of calling surf::Request::body
in the TryFrom
implementation, which is defaulting the Content-Type
header to application/octet-stream
.
The question is why the TryFrom
implementation for surf::Request
doesn't just construct using the passed in request, for example:
fn try_from(http_request: http_types::Request) -> io::Result<Self> {
let url = http_request.url().clone();
let req = Self {
fut: None,
client: Some(Client::new()),
req: Some(http_request),
url,
middleware: Some(vec![]),
};
#[cfg(feature = "middleware-logger")]
let req = req.middleware(crate::middleware::logger::new());
Ok(req)
}
Also, given that currently the TryFrom
implementation can't fail, perhaps we could turn this into From
for ergonomics?
perhaps we could turn this into From for ergonomics?
Yes, absolutely!
If you convert from
http_types::Request
tosurf::Request
usingsurf::Request::try_from(http_types::Request)
, the content-type doesn't get coped over correctly. Below is my Cargo.toml and src/lib.rs, with a test that duplicates the error.