http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.46k stars 120 forks source link

Runtime panic with alpha.3 when setting header #183

Closed jamwaffles closed 4 years ago

jamwaffles commented 4 years ago

I'm getting a panic at runtime when attempting to set a header on a Request. I could be misusing the library so please let me know if that's the case.

It looks like the error might be coming from http_types::Request::insert_header.

I've tried cargo clean/rm Cargo.lock/cargo build to no avail.

The following code panics at runtime in alpha.3:

let response = surf::Request::new(method, url)
    .set_header("Content-Type", "application/json")
    .recv_json().await?;

The pertinent information from the backtrace appears to be this:

surf::request::Request<C>::set_header
    /home/james/.cargo/registry/src/github.com-1ecc6299db9ec823/surf-2.0.0-alpha.3/src/request.rs:200

If I comment out the set_header line, the request goes through (although the recv_json breaks now because the server doesn't respond properly).

The following code works in alpha.2:

let response = surf::Request::new(method, url)
    .set_header("Content-Type".parse().unwrap(), "application/json")
    .recv_json().await?;
Licenser commented 4 years ago

~Give this a try~ I stand corrected,the same happens with the http_ytpes::headers

let response = surf::Request::new(method, url)
    .set_header(http_types::headers::CONTENT_TYPE, "application/json")
    .recv_json().await?;
jamwaffles commented 4 years ago

Thanks for fixing this! Looking forward to the next release :)