mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
fix ssl test server
This commit is contained in:
parent
dffb7936fb
commit
844be8d9dd
@ -192,7 +192,7 @@ impl StreamHandlerType {
|
|||||||
let io = TcpStream::from_std(io, &Handle::default())
|
let io = TcpStream::from_std(io, &Handle::default())
|
||||||
.expect("failed to associate TCP stream");
|
.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| {
|
move |res| {
|
||||||
match res {
|
match res {
|
||||||
Ok(io) => current_thread::spawn(HttpChannel::new(
|
Ok(io) => current_thread::spawn(HttpChannel::new(
|
||||||
@ -213,7 +213,7 @@ impl StreamHandlerType {
|
|||||||
let io = TcpStream::from_std(io, &Handle::default())
|
let io = TcpStream::from_std(io, &Handle::default())
|
||||||
.expect("failed to associate TCP stream");
|
.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| {
|
move |res| {
|
||||||
match res {
|
match res {
|
||||||
Ok(io) => {
|
Ok(io) => {
|
||||||
|
24
src/test.rs
24
src/test.rs
@ -14,7 +14,7 @@ use net2::TcpBuilder;
|
|||||||
use tokio::runtime::current_thread::Runtime;
|
use tokio::runtime::current_thread::Runtime;
|
||||||
|
|
||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
use openssl::ssl::SslAcceptor;
|
use openssl::ssl::SslAcceptorBuilder;
|
||||||
|
|
||||||
use application::{App, HttpApplication};
|
use application::{App, HttpApplication};
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
@ -251,7 +251,7 @@ impl Drop for TestServer {
|
|||||||
pub struct TestServerBuilder<S> {
|
pub struct TestServerBuilder<S> {
|
||||||
state: Box<Fn() -> S + Sync + Send + 'static>,
|
state: Box<Fn() -> S + Sync + Send + 'static>,
|
||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
ssl: Option<SslAcceptor>,
|
ssl: Option<SslAcceptorBuilder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static> TestServerBuilder<S> {
|
impl<S: 'static> TestServerBuilder<S> {
|
||||||
@ -268,7 +268,7 @@ impl<S: 'static> TestServerBuilder<S> {
|
|||||||
|
|
||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
/// Create ssl server
|
/// Create ssl server
|
||||||
pub fn ssl(mut self, ssl: SslAcceptor) -> Self {
|
pub fn ssl(mut self, ssl: SslAcceptorBuilder) -> Self {
|
||||||
self.ssl = Some(ssl);
|
self.ssl = Some(ssl);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -291,10 +291,9 @@ impl<S: 'static> TestServerBuilder<S> {
|
|||||||
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 state = self.state;
|
|
||||||
|
|
||||||
System::new("actix-test-server")
|
System::new("actix-test-server")
|
||||||
.config(move || {
|
.config(move || {
|
||||||
|
let state = self.state;
|
||||||
let srv = HttpServer::new(move || {
|
let srv = HttpServer::new(move || {
|
||||||
let mut app = TestApp::new(state());
|
let mut app = TestApp::new(state());
|
||||||
config(&mut app);
|
config(&mut app);
|
||||||
@ -311,22 +310,11 @@ impl<S: 'static> TestServerBuilder<S> {
|
|||||||
|
|
||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
{
|
{
|
||||||
use futures::Stream;
|
|
||||||
use std::io;
|
|
||||||
use tokio_openssl::SslAcceptorExt;
|
|
||||||
|
|
||||||
let ssl = self.ssl.take();
|
let ssl = self.ssl.take();
|
||||||
if let Some(ssl) = ssl {
|
if let Some(ssl) = ssl {
|
||||||
srv.start_incoming(
|
srv.listen_ssl(tcp, ssl).unwrap().start();
|
||||||
tcp.incoming().and_then(move |sock| {
|
|
||||||
ssl.accept_async(sock).map_err(|e| {
|
|
||||||
io::Error::new(io::ErrorKind::Other, e)
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
srv.start_incoming(tcp.incoming(), false);
|
srv.listen(tcp).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "alpn"))]
|
#[cfg(not(feature = "alpn"))]
|
||||||
|
@ -227,7 +227,7 @@ fn test_ws_server_ssl() {
|
|||||||
.set_certificate_chain_file("tests/cert.pem")
|
.set_certificate_chain_file("tests/cert.pem")
|
||||||
.unwrap();
|
.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| {
|
app.handler(|req| {
|
||||||
ws::start(
|
ws::start(
|
||||||
req,
|
req,
|
||||||
|
Loading…
Reference in New Issue
Block a user