Request with HTTP 1.0 hangs
JamesSharkey opened this issue · comments
Hello, I'm testing a client that makes a HTTP 1.0 request. When making the HTTP 1.0 request to mockito it hangs.
use reqwest::{Client, Version, Response};
async fn request_with_version(url: &str, version: Version) -> reqwest::Result<Response> {
let client = Client::new();
client.head(url).version(version).send().await
}
#[cfg(test)]
mod tests {
use super::*;
use mockito::mock;
use mockito::server_url;
#[tokio::test]
async fn test_with_reqwest() {
let _m = mock("HEAD", "/")
.with_body(b"some bytes")
.create();
let response = request_with_version(&server_url(), Version::HTTP_11).await.unwrap();
println!("{:?}", response);
// Request below never returns
let response = request_with_version(&server_url(), Version::HTTP_10).await.unwrap();
println!("{:?}", response);
}
}
Dependencies:
[dependencies]
mockito = "0.30.0"
reqwest = "0.11.4"
tokio = { version = "1.0.2", features = ["macros"] }
I cloned the mockito repo and added the test below which passed.
#[test]
fn test_propagate_protocol_to_response_head() {
let _mock = mock("HEAD", "/").create();
let stream = request_stream("1.0", "HEAD /", "", "");
stream.shutdown(Shutdown::Write).unwrap();
let (status_line, _, _) = parse_stream(stream, true);
assert_eq!("HTTP/1.0 200 OK\r\n", status_line);
}
@JamesSharkey Thanks for reporting. I don't have the capacity to work on this in the near future but I would gladly review a PR on this topic if you or someone else is willing to contribute.
This might be fixed in https://github.com/lipanski/mockito/releases/tag/0.32.0 - please give it a try if it's still of interest.