fix(client): coerce HTTP_2 requests to HTTP_11

Closes #1770
This commit is contained in:
Sean McArthur
2019-02-27 16:55:39 -08:00
parent 2b0a5eaa04
commit 3a6080b14a
3 changed files with 99 additions and 14 deletions

View File

@@ -236,13 +236,14 @@ where C: Connect + Sync + 'static,
match req.version() {
Version::HTTP_11 => (),
Version::HTTP_10 => if is_http_connect {
debug!("CONNECT is not allowed for HTTP/1.0");
warn!("CONNECT is not allowed for HTTP/1.0");
return ResponseFuture::new(Box::new(future::err(::Error::new_user_unsupported_request_method())));
},
other => if self.config.ver != Ver::Http2 {
error!("Request has unsupported version \"{:?}\"", other);
return ResponseFuture::new(Box::new(future::err(::Error::new_user_unsupported_version())));
}
other_h2 @ Version::HTTP_2 => if self.config.ver != Ver::Http2 {
return ResponseFuture::error_version(other_h2);
},
// completely unsupported HTTP version (like HTTP/0.9)!
other => return ResponseFuture::error_version(other),
};
let domain = match extract_domain(req.uri_mut(), is_http_connect) {
@@ -591,6 +592,11 @@ impl ResponseFuture {
inner: fut,
}
}
fn error_version(ver: Version) -> Self {
warn!("Request has unsupported version \"{:?}\"", ver);
ResponseFuture::new(Box::new(future::err(::Error::new_user_unsupported_version())))
}
}
impl fmt::Debug for ResponseFuture {

View File

@@ -271,7 +271,7 @@ impl Http1Transaction for Server {
warn!("response with HTTP2 version coerced to HTTP/1.1");
extend(dst, b"HTTP/1.1 ");
},
_ => unreachable!(),
other => panic!("unexpected response version: {:?}", other),
}
extend(dst, msg.head.subject.as_str().as_bytes());
@@ -667,7 +667,11 @@ impl Http1Transaction for Client {
match msg.head.version {
Version::HTTP_10 => extend(dst, b"HTTP/1.0"),
Version::HTTP_11 => extend(dst, b"HTTP/1.1"),
_ => unreachable!(),
Version::HTTP_2 => {
warn!("request with HTTP2 version coerced to HTTP/1.1");
extend(dst, b"HTTP/1.1");
},
other => panic!("unexpected request version: {:?}", other),
}
extend(dst, b"\r\n");