mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
restore rust-tls support
This commit is contained in:
parent
ecfda64f6d
commit
1ff86e5ac4
@ -32,12 +32,12 @@ script:
|
|||||||
- |
|
- |
|
||||||
if [[ "$TRAVIS_RUST_VERSION" != "stable" ]]; then
|
if [[ "$TRAVIS_RUST_VERSION" != "stable" ]]; then
|
||||||
cargo clean
|
cargo clean
|
||||||
cargo test --features="ssl,tls" -- --nocapture
|
cargo test --features="ssl,tls,rust-tls" -- --nocapture
|
||||||
fi
|
fi
|
||||||
- |
|
- |
|
||||||
if [[ "$TRAVIS_RUST_VERSION" == "stable" ]]; then
|
if [[ "$TRAVIS_RUST_VERSION" == "stable" ]]; then
|
||||||
RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install -f cargo-tarpaulin
|
RUSTFLAGS="--cfg procmacro2_semver_exempt" cargo install -f cargo-tarpaulin
|
||||||
cargo tarpaulin --features="ssl,tls" --out Xml --no-count
|
cargo tarpaulin --features="ssl,tls,rust-tls" --out Xml --no-count
|
||||||
bash <(curl -s https://codecov.io/bash)
|
bash <(curl -s https://codecov.io/bash)
|
||||||
echo "Uploaded code coverage"
|
echo "Uploaded code coverage"
|
||||||
fi
|
fi
|
||||||
@ -46,7 +46,7 @@ script:
|
|||||||
after_success:
|
after_success:
|
||||||
- |
|
- |
|
||||||
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "beta" ]]; then
|
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "beta" ]]; then
|
||||||
cargo doc --features "ssl,session" --no-deps &&
|
cargo doc --features "ssl,tls,rust-tls,session" --no-deps &&
|
||||||
echo "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > target/doc/index.html &&
|
echo "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > target/doc/index.html &&
|
||||||
git clone https://github.com/davisp/ghp-import.git &&
|
git clone https://github.com/davisp/ghp-import.git &&
|
||||||
./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc &&
|
./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc &&
|
||||||
|
@ -15,8 +15,8 @@ use native_tls::TlsAcceptor;
|
|||||||
#[cfg(any(feature = "alpn", feature = "ssl"))]
|
#[cfg(any(feature = "alpn", feature = "ssl"))]
|
||||||
use openssl::ssl::SslAcceptorBuilder;
|
use openssl::ssl::SslAcceptorBuilder;
|
||||||
|
|
||||||
//#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
//use rustls::ServerConfig;
|
use rustls::ServerConfig;
|
||||||
|
|
||||||
use super::acceptor::{AcceptorServiceFactory, DefaultAcceptor};
|
use super::acceptor::{AcceptorServiceFactory, DefaultAcceptor};
|
||||||
use super::builder::DefaultPipelineFactory;
|
use super::builder::DefaultPipelineFactory;
|
||||||
@ -313,22 +313,38 @@ where
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
// /// Use listener for accepting incoming tls connection requests
|
/// Use listener for accepting incoming tls connection requests
|
||||||
// ///
|
///
|
||||||
// /// This method sets alpn protocols to "h2" and "http/1.1"
|
/// This method sets alpn protocols to "h2" and "http/1.1"
|
||||||
// pub fn listen_rustls(self, lst: net::TcpListener, builder: ServerConfig) -> Self {
|
pub fn listen_rustls(mut self, lst: net::TcpListener, config: ServerConfig) -> Self {
|
||||||
// use super::{RustlsAcceptor, ServerFlags};
|
use super::{RustlsAcceptor, ServerFlags};
|
||||||
|
use actix_net::service::NewServiceExt;
|
||||||
|
|
||||||
// // alpn support
|
// alpn support
|
||||||
// let flags = if self.no_http2 {
|
let flags = if self.no_http2 {
|
||||||
// ServerFlags::HTTP1
|
ServerFlags::HTTP1
|
||||||
// } else {
|
} else {
|
||||||
// ServerFlags::HTTP1 | ServerFlags::HTTP2
|
ServerFlags::HTTP1 | ServerFlags::HTTP2
|
||||||
// };
|
};
|
||||||
//
|
|
||||||
// self.listen_with(lst, RustlsAcceptor::with_flags(builder, flags))
|
let addr = lst.local_addr().unwrap();
|
||||||
// }
|
self.sockets.push(Socket {
|
||||||
|
lst,
|
||||||
|
addr,
|
||||||
|
scheme: "https",
|
||||||
|
handler: Box::new(HttpServiceBuilder::new(
|
||||||
|
self.factory.clone(),
|
||||||
|
move || {
|
||||||
|
RustlsAcceptor::with_flags(config.clone(), flags).map_err(|_| ())
|
||||||
|
},
|
||||||
|
DefaultPipelineFactory::new(),
|
||||||
|
)),
|
||||||
|
});
|
||||||
|
|
||||||
|
//Ok(self)
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// The socket address to bind
|
/// The socket address to bind
|
||||||
///
|
///
|
||||||
|
@ -6,7 +6,7 @@ pub use self::openssl::*;
|
|||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
mod nativetls;
|
mod nativetls;
|
||||||
|
|
||||||
//#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
//mod rustls;
|
mod rustls;
|
||||||
//#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
//pub use self::rustls::RustlsAcceptor;
|
pub use self::rustls::RustlsAcceptor;
|
||||||
|
@ -1,29 +1,25 @@
|
|||||||
use std::net::Shutdown;
|
use std::net::Shutdown;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::{io, time};
|
use std::{io, time};
|
||||||
|
|
||||||
|
use actix_net::ssl; //::RustlsAcceptor;
|
||||||
use rustls::{ClientSession, ServerConfig, ServerSession};
|
use rustls::{ClientSession, ServerConfig, ServerSession};
|
||||||
use tokio_io::AsyncWrite;
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
use tokio_rustls::{AcceptAsync, ServerConfigExt, TlsStream};
|
use tokio_rustls::TlsStream;
|
||||||
|
|
||||||
use server::{AcceptorService, IoStream, ServerFlags};
|
use server::{IoStream, ServerFlags};
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
/// Support `SSL` connections via rustls package
|
/// Support `SSL` connections via rustls package
|
||||||
///
|
///
|
||||||
/// `rust-tls` feature enables `RustlsAcceptor` type
|
/// `rust-tls` feature enables `RustlsAcceptor` type
|
||||||
pub struct RustlsAcceptor {
|
pub struct RustlsAcceptor<T> {
|
||||||
config: Arc<ServerConfig>,
|
_t: ssl::RustlsAcceptor<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustlsAcceptor {
|
impl<T: AsyncRead + AsyncWrite> RustlsAcceptor<T> {
|
||||||
/// Create `OpensslAcceptor` with enabled `HTTP/2` and `HTTP1.1` support.
|
/// Create `RustlsAcceptor` with custom server flags.
|
||||||
pub fn new(config: ServerConfig) -> Self {
|
pub fn with_flags(
|
||||||
RustlsAcceptor::with_flags(config, ServerFlags::HTTP1 | ServerFlags::HTTP2)
|
mut config: ServerConfig, flags: ServerFlags,
|
||||||
}
|
) -> ssl::RustlsAcceptor<T> {
|
||||||
|
|
||||||
/// Create `OpensslAcceptor` with custom server flags.
|
|
||||||
pub fn with_flags(mut config: ServerConfig, flags: ServerFlags) -> Self {
|
|
||||||
let mut protos = Vec::new();
|
let mut protos = Vec::new();
|
||||||
if flags.contains(ServerFlags::HTTP2) {
|
if flags.contains(ServerFlags::HTTP2) {
|
||||||
protos.push("h2".to_string());
|
protos.push("h2".to_string());
|
||||||
@ -35,22 +31,7 @@ impl RustlsAcceptor {
|
|||||||
config.set_protocols(&protos);
|
config.set_protocols(&protos);
|
||||||
}
|
}
|
||||||
|
|
||||||
RustlsAcceptor {
|
ssl::RustlsAcceptor::new(config)
|
||||||
config: Arc::new(config),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Io: IoStream> AcceptorService<Io> for RustlsAcceptor {
|
|
||||||
type Accepted = TlsStream<Io, ServerSession>;
|
|
||||||
type Future = AcceptAsync<Io>;
|
|
||||||
|
|
||||||
fn scheme(&self) -> &'static str {
|
|
||||||
"https"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn accept(&self, io: Io) -> Self::Future {
|
|
||||||
ServerConfigExt::accept_async(&self.config, io)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ use openssl::ssl::SslAcceptorBuilder;
|
|||||||
use rustls::ServerConfig;
|
use rustls::ServerConfig;
|
||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
use server::OpensslAcceptor;
|
use server::OpensslAcceptor;
|
||||||
#[cfg(feature = "rust-tls")]
|
|
||||||
use server::RustlsAcceptor;
|
|
||||||
|
|
||||||
use application::{App, HttpApplication};
|
use application::{App, HttpApplication};
|
||||||
use body::Binary;
|
use body::Binary;
|
||||||
@ -350,7 +348,7 @@ where
|
|||||||
let ssl = self.rust_ssl.take();
|
let ssl = self.rust_ssl.take();
|
||||||
if let Some(ssl) = ssl {
|
if let Some(ssl) = ssl {
|
||||||
let tcp = net::TcpListener::bind(addr).unwrap();
|
let tcp = net::TcpListener::bind(addr).unwrap();
|
||||||
srv = srv.listen_with(tcp, RustlsAcceptor::new(ssl));
|
srv = srv.listen_rustls(tcp, ssl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !has_ssl {
|
if !has_ssl {
|
||||||
|
Loading…
Reference in New Issue
Block a user