diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index e2a1131d46..fb0a38c6f2 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -267,6 +267,10 @@ impl Http1Transaction for Server { match msg.head.version { Version::HTTP_10 => extend(dst, b"HTTP/1.0 "), Version::HTTP_11 => extend(dst, b"HTTP/1.1 "), + Version::HTTP_2 => { + warn!("response with HTTP2 version coerced to HTTP/1.1"); + extend(dst, b"HTTP/1.1 "); + }, _ => unreachable!(), } diff --git a/tests/server.rs b/tests/server.rs index 089b44513b..fd31a5ac07 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1542,6 +1542,25 @@ fn streaming_body() { rt.block_on(fut.join(rx)).unwrap(); } +#[test] +fn http1_response_with_http2_version() { + let server = serve(); + let addr_str = format!("http://{}", server.addr()); + + let mut rt = Runtime::new().expect("runtime new"); + + server + .reply() + .version(hyper::Version::HTTP_2); + + rt.block_on(hyper::rt::lazy(move || { + let client = Client::new(); + let uri = addr_str.parse().expect("server addr should parse"); + + client.get(uri) + })).unwrap(); +} + #[test] fn try_h2() { let server = serve(); @@ -1641,6 +1660,11 @@ impl<'a> ReplyBuilder<'a> { self } + fn version(self, version: hyper::Version) -> Self { + self.tx.send(Reply::Version(version)).unwrap(); + self + } + fn header>(self, name: &str, value: V) -> Self { let name = HeaderName::from_bytes(name.as_bytes()).expect("header name"); let value = HeaderValue::from_str(value.as_ref()).expect("header value"); @@ -1681,6 +1705,7 @@ struct TestService { #[derive(Debug)] enum Reply { Status(hyper::StatusCode), + Version(hyper::Version), Header(HeaderName, HeaderValue), Body(hyper::Body), End, @@ -1718,6 +1743,9 @@ impl TestService { Reply::Status(s) => { *res.status_mut() = s; }, + Reply::Version(v) => { + *res.version_mut() = v; + }, Reply::Header(name, value) => { res.headers_mut().insert(name, value); },