feat(server): support HTTP1 and HTTP2 automatically
If an HTTP/1 connection has a parse error, but it starts with the HTTP2 preface, converts the connection automatically into an HTTP2 server connection. Closes #1486
This commit is contained in:
@@ -31,6 +31,7 @@ use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
|
||||
use hyper::{Body, Request, Response, StatusCode};
|
||||
use hyper::client::Client;
|
||||
use hyper::server::conn::Http;
|
||||
use hyper::service::{service_fn, Service};
|
||||
|
||||
@@ -39,6 +40,24 @@ fn tcp_bind(addr: &SocketAddr, handle: &Handle) -> ::tokio::io::Result<TcpListen
|
||||
TcpListener::from_std(std_listener, handle)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_h2() {
|
||||
let server = serve();
|
||||
let addr_str = format!("http://{}", server.addr());
|
||||
|
||||
hyper::rt::run(hyper::rt::lazy(move || {
|
||||
let client: Client<_, hyper::Body> = Client::builder().http2_only(true).build_http();
|
||||
let uri = addr_str.parse::<hyper::Uri>().expect("server addr should parse");
|
||||
|
||||
client.get(uri)
|
||||
.and_then(|_res| { Ok(()) })
|
||||
.map(|_| { () })
|
||||
.map_err(|_e| { () })
|
||||
}));
|
||||
|
||||
assert_eq!(server.body(), b"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_should_ignore_body() {
|
||||
let server = serve();
|
||||
|
||||
Reference in New Issue
Block a user