1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-18 15:41:17 +00:00

fix ssl test server

This commit is contained in:
Nikolay Kim 2018-05-29 10:59:24 -07:00
parent dffb7936fb
commit 844be8d9dd
3 changed files with 9 additions and 21 deletions

View file

@ -192,7 +192,7 @@ impl StreamHandlerType {
let io = TcpStream::from_std(io, &Handle::default())
.expect("failed to associate TCP stream");
Arbiter::spawn(TlsAcceptorExt::accept_async(acceptor, io).then(
current_thread::spawn(TlsAcceptorExt::accept_async(acceptor, io).then(
move |res| {
match res {
Ok(io) => current_thread::spawn(HttpChannel::new(
@ -213,7 +213,7 @@ impl StreamHandlerType {
let io = TcpStream::from_std(io, &Handle::default())
.expect("failed to associate TCP stream");
Arbiter::spawn(SslAcceptorExt::accept_async(acceptor, io).then(
current_thread::spawn(SslAcceptorExt::accept_async(acceptor, io).then(
move |res| {
match res {
Ok(io) => {

View file

@ -14,7 +14,7 @@ use net2::TcpBuilder;
use tokio::runtime::current_thread::Runtime;
#[cfg(feature = "alpn")]
use openssl::ssl::SslAcceptor;
use openssl::ssl::SslAcceptorBuilder;
use application::{App, HttpApplication};
use body::Binary;
@ -251,7 +251,7 @@ impl Drop for TestServer {
pub struct TestServerBuilder<S> {
state: Box<Fn() -> S + Sync + Send + 'static>,
#[cfg(feature = "alpn")]
ssl: Option<SslAcceptor>,
ssl: Option<SslAcceptorBuilder>,
}
impl<S: 'static> TestServerBuilder<S> {
@ -268,7 +268,7 @@ impl<S: 'static> TestServerBuilder<S> {
#[cfg(feature = "alpn")]
/// Create ssl server
pub fn ssl(mut self, ssl: SslAcceptor) -> Self {
pub fn ssl(mut self, ssl: SslAcceptorBuilder) -> Self {
self.ssl = Some(ssl);
self
}
@ -291,10 +291,9 @@ impl<S: 'static> TestServerBuilder<S> {
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
let local_addr = tcp.local_addr().unwrap();
let state = self.state;
System::new("actix-test-server")
.config(move || {
let state = self.state;
let srv = HttpServer::new(move || {
let mut app = TestApp::new(state());
config(&mut app);
@ -311,22 +310,11 @@ impl<S: 'static> TestServerBuilder<S> {
#[cfg(feature = "alpn")]
{
use futures::Stream;
use std::io;
use tokio_openssl::SslAcceptorExt;
let ssl = self.ssl.take();
if let Some(ssl) = ssl {
srv.start_incoming(
tcp.incoming().and_then(move |sock| {
ssl.accept_async(sock).map_err(|e| {
io::Error::new(io::ErrorKind::Other, e)
})
}),
false,
);
srv.listen_ssl(tcp, ssl).unwrap().start();
} else {
srv.start_incoming(tcp.incoming(), false);
srv.listen(tcp).start();
}
}
#[cfg(not(feature = "alpn"))]

View file

@ -227,7 +227,7 @@ fn test_ws_server_ssl() {
.set_certificate_chain_file("tests/cert.pem")
.unwrap();
let mut srv = test::TestServer::build().ssl(builder.build()).start(|app| {
let mut srv = test::TestServer::build().ssl(builder).start(|app| {
app.handler(|req| {
ws::start(
req,