mirror of
https://github.com/actix/actix-web.git
synced 2024-11-26 11:31:09 +00:00
allow to disable http/2 support
This commit is contained in:
parent
b16f2d5f05
commit
4096089a3f
5 changed files with 31 additions and 15 deletions
|
@ -1,6 +1,8 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## 0.4.9 (2018-03-xx)
|
## 0.4.9 (2018-03-16)
|
||||||
|
|
||||||
|
* Allow to disable http/2 support
|
||||||
|
|
||||||
* Wake payload reading task when data is available
|
* Wake payload reading task when data is available
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ pub struct HttpServer<H> where H: IntoHttpHandler + 'static
|
||||||
exit: bool,
|
exit: bool,
|
||||||
shutdown_timeout: u16,
|
shutdown_timeout: u16,
|
||||||
signals: Option<Addr<Syn, signal::ProcessSignals>>,
|
signals: Option<Addr<Syn, signal::ProcessSignals>>,
|
||||||
|
no_http2: bool,
|
||||||
no_signals: bool,
|
no_signals: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +90,7 @@ impl<H> HttpServer<H> where H: IntoHttpHandler + 'static
|
||||||
exit: false,
|
exit: false,
|
||||||
shutdown_timeout: 30,
|
shutdown_timeout: 30,
|
||||||
signals: None,
|
signals: None,
|
||||||
|
no_http2: false,
|
||||||
no_signals: false,
|
no_signals: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,6 +172,12 @@ impl<H> HttpServer<H> where H: IntoHttpHandler + 'static
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Disable `HTTP/2` support
|
||||||
|
pub fn no_http2(mut self) -> Self {
|
||||||
|
self.no_http2 = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Get addresses of bound sockets.
|
/// Get addresses of bound sockets.
|
||||||
pub fn addrs(&self) -> Vec<net::SocketAddr> {
|
pub fn addrs(&self) -> Vec<net::SocketAddr> {
|
||||||
self.sockets.iter().map(|s| s.0).collect()
|
self.sockets.iter().map(|s| s.0).collect()
|
||||||
|
@ -396,15 +404,17 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
|
Err(io::Error::new(io::ErrorKind::Other, "No socket addresses are bound"))
|
||||||
} else {
|
} else {
|
||||||
// alpn support
|
// alpn support
|
||||||
builder.set_alpn_protos(b"\x02h2\x08http/1.1")?;
|
if !self.no_http2 {
|
||||||
builder.set_alpn_select_callback(|_, protos| {
|
builder.set_alpn_protos(b"\x02h2\x08http/1.1")?;
|
||||||
const H2: &[u8] = b"\x02h2";
|
builder.set_alpn_select_callback(|_, protos| {
|
||||||
if protos.windows(3).any(|window| window == H2) {
|
const H2: &[u8] = b"\x02h2";
|
||||||
Ok(b"h2")
|
if protos.windows(3).any(|window| window == H2) {
|
||||||
} else {
|
Ok(b"h2")
|
||||||
Err(AlpnError::NOACK)
|
} else {
|
||||||
}
|
Err(AlpnError::NOACK)
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let (tx, rx) = mpsc::unbounded();
|
let (tx, rx) = mpsc::unbounded();
|
||||||
let acceptor = builder.build();
|
let acceptor = builder.build();
|
||||||
|
|
|
@ -204,7 +204,8 @@ impl StreamHandlerType {
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
Arbiter::handle().spawn(HttpChannel::new(h, io, peer, http2));
|
Arbiter::handle().spawn(
|
||||||
|
HttpChannel::new(h, io, peer, http2));
|
||||||
},
|
},
|
||||||
Err(err) =>
|
Err(err) =>
|
||||||
trace!("Error during handling tls connection: {}", err),
|
trace!("Error during handling tls connection: {}", err),
|
||||||
|
|
|
@ -87,9 +87,12 @@ impl TestServer {
|
||||||
let sys = System::new("actix-test-server");
|
let sys = System::new("actix-test-server");
|
||||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||||
let local_addr = tcp.local_addr().unwrap();
|
let local_addr = tcp.local_addr().unwrap();
|
||||||
let tcp = TcpListener::from_listener(tcp, &local_addr, Arbiter::handle()).unwrap();
|
let tcp = TcpListener::from_listener(
|
||||||
|
tcp, &local_addr, Arbiter::handle()).unwrap();
|
||||||
|
|
||||||
HttpServer::new(factory).disable_signals().start_incoming(tcp.incoming(), false);
|
HttpServer::new(factory)
|
||||||
|
.disable_signals()
|
||||||
|
.start_incoming(tcp.incoming(), false);
|
||||||
|
|
||||||
tx.send((Arbiter::system(), local_addr)).unwrap();
|
tx.send((Arbiter::system(), local_addr)).unwrap();
|
||||||
let _ = sys.run();
|
let _ = sys.run();
|
||||||
|
|
|
@ -742,8 +742,8 @@ fn test_h2() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
let _res = core.run(tcp);
|
let res = core.run(tcp);
|
||||||
// assert_eq!(_res.unwrap(), Bytes::from_static(STR.as_ref()));
|
assert_eq!(res.unwrap(), Bytes::from_static(STR.as_ref()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue