1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-05 01:29:36 +00:00

fixes and add changes

This commit is contained in:
Marat Safin 2019-07-30 20:54:00 +03:00
parent 5c516f7ddc
commit 7492ef4a2e
16 changed files with 31 additions and 180 deletions

View file

@ -5,6 +5,7 @@
### Changed
* Add `Clone` impl for `HeaderMap`
* Add `rustls` support
### Fixed

View file

@ -1,6 +1,6 @@
[package]
name = "actix-http"
version = "0.2.7"
version = "0.2.8"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix http primitives"
readme = "README.md"

View file

@ -25,14 +25,14 @@ use rustls::ClientConfig;
use std::sync::Arc;
#[cfg(any(feature = "ssl", feature = "rust-tls"))]
pub enum SslConnector {
enum SslConnector {
#[cfg(feature = "ssl")]
Openssl(OpensslConnector),
#[cfg(feature = "rust-tls")]
Rustls(Arc<ClientConfig>),
}
#[cfg(not(any(feature = "ssl", feature = "rust-tls")))]
pub type SslConnector = ();
type SslConnector = ();
/// Manages http client network connectivity
/// The `Connector` type uses a builder-like combinator pattern for service
@ -150,10 +150,16 @@ where
self
}
#[cfg(any(feature = "ssl", feature = "rust-tls"))]
#[cfg(feature = "ssl")]
/// Use custom `SslConnector` instance.
pub fn ssl(mut self, connector: SslConnector) -> Self {
self.ssl = connector;
pub fn ssl(mut self, connector: OpensslConnector) -> Self {
self.ssl = SslConnector::Openssl(connector);
self
}
#[cfg(feature = "rust-tls")]
pub fn rustls(mut self, connector: Arc<ClientConfig>) -> Self {
self.ssl = SslConnector::Rustls(connector);
self
}
@ -325,76 +331,6 @@ where
),
}
}
// #[cfg(feature = "rust-tls")]
// {
// const H2: &[u8] = b"h2";
// use actix_connect::ssl::RustlsConnector;
// use rustls::Session;
// let ssl = match self.ssl {
// SslConnector::Rustls(ssl) => ssl,
// _ => unimplemented!(),
// };
// let ssl_service = TimeoutService::new(
// self.timeout,
// apply_fn(self.connector.clone(), |msg: Connect, srv| {
// srv.call(TcpConnect::new(msg.uri).set_addr(msg.addr))
// })
// .map_err(ConnectError::from)
// .and_then(
// RustlsConnector::service(ssl)
// .map_err(ConnectError::from)
// .map(|stream| {
// let sock = stream.into_parts().0;
// let h2 = sock
// .get_ref()
// .1
// .get_alpn_protocol()
// .map(|protos| protos.windows(2).any(|w| w == H2))
// .unwrap_or(false);
// if h2 {
// (sock, Protocol::Http2)
// } else {
// (sock, Protocol::Http1)
// }
// }),
// ),
// )
// .map_err(|e| match e {
// TimeoutError::Service(e) => e,
// TimeoutError::Timeout => ConnectError::Timeout,
// });
// let tcp_service = TimeoutService::new(
// self.timeout,
// apply_fn(self.connector.clone(), |msg: Connect, srv| {
// srv.call(TcpConnect::new(msg.uri).set_addr(msg.addr))
// })
// .map_err(ConnectError::from)
// .map(|stream| (stream.into_parts().0, Protocol::Http1)),
// )
// .map_err(|e| match e {
// TimeoutError::Service(e) => e,
// TimeoutError::Timeout => ConnectError::Timeout,
// });
// connect_impl::InnerConnector {
// tcp_pool: ConnectionPool::new(
// tcp_service,
// self.conn_lifetime,
// self.conn_keep_alive,
// None,
// self.limit,
// ),
// ssl_pool: Some(ConnectionPool::new(
// ssl_service,
// self.conn_lifetime,
// self.conn_keep_alive,
// Some(self.disconnect_timeout),
// self.limit,
// )),
// }
// }
}
}

View file

@ -9,7 +9,7 @@ mod h2proto;
mod pool;
pub use self::connection::Connection;
pub use self::connector::{Connector, SslConnector};
pub use self::connector::Connector;
pub use self::error::{ConnectError, InvalidUrl, SendRequestError};
pub use self::pool::Protocol;

View file

@ -1,32 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIFfjCCA2agAwIBAgIJAOIBvp/w68KrMA0GCSqGSIb3DQEBCwUAMGsxCzAJBgNV
BAYTAlJVMRkwFwYDVQQIDBBTYWludC1QZXRlcnNidXJnMRkwFwYDVQQHDBBTYWlu
dC1QZXRlcnNidXJnMRIwEAYDVQQKDAlLdXBpYmlsZXQxEjAQBgNVBAMMCWxvY2Fs
aG9zdDAgFw0xOTA3MjcxODIzMTJaGA8z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QNlr/VEfIw2Dahnve9hcLWtNDkdRnTZ
IPlMoCmfzVo6pHIU0uy1MKEX7Js6YYnnsPVevhLR6NmTQU73NDRPVOzfOGUc+RDw
LXTxIBgQqAy/+ORIiNDwUxSSDgcSi7DG14qD9c0l59WH/HpI276Cc/4lPA9kl4/5
X0MlvheFm+BCcgG34Wa1A0Y3JXkl3NqU94oktDro1or3NYioaPTGyR4MYaUPJh7f
SV2TacsP/ql5ks7xahkeB9un0ddOfBcWa6PqH1a7U6rnPj63mVB4hpGvhrziSiB/
s6ECggEAOp2P4Yd9Vm9/CptxS50HFF4adyLscAtsDd3S2hIAXhDovcPbvRek4pLQ
idPhHlRAfqrEztnhaVAmCK9HlhgthtiQGQX62YI4CS4QL2IhzDFo3M1a2snjFEdl
QuFk3XI7kQ0Yp8BLLG7T436JUrUkCXc4gQX2uRNut+ff34RIR2CjcQQjChxuHVeG
sP/3xFFj8OSs7ZoSPbmDBLrMOl64YHwezQUNAZiRYiaGbFiY0QUV6dHq8qX/qE1h
a/0Rq+gTqObDST0TqhMzI8V/i7R8SwVcD5ODHaZp5I2N2P/hV5OWY7ghQXhh89WM
o21xtGh0nP2Fq1TC6jFO+9cpbK8jNA==
-----END PRIVATE KEY-----

View file

@ -30,8 +30,8 @@ where
fn ssl_acceptor<T: AsyncRead + AsyncWrite>() -> Result<RustlsAcceptor<T, ()>> {
// load ssl keys
let mut config = RustlsServerConfig::new(NoClientAuth::new());
let cert_file = &mut BufReader::new(File::open("tests/cert.pem").unwrap());
let key_file = &mut BufReader::new(File::open("tests/key.pem").unwrap());
let cert_file = &mut BufReader::new(File::open("../tests/cert.pem").unwrap());
let key_file = &mut BufReader::new(File::open("../tests/key.pem").unwrap());
let cert_chain = certs(cert_file).unwrap();
let mut keys = pkcs8_private_keys(key_file).unwrap();
config.set_single_cert(cert_chain, keys.remove(0)).unwrap();

View file

@ -142,7 +142,6 @@ fn test_body() {
assert!(response.status().is_success());
assert_eq!(response.status(), http::StatusCode::NO_CONTENT);
// let mut srv = TestServer::new(|| HttpService::new(App::new().service(auto_sync)));
let request = srv.request(http::Method::GET, srv.url("/test"));
let response = srv.block_on(request.send()).unwrap();
assert!(response.status().is_success());

View file

@ -1,5 +1,9 @@
# Changes
## [0.2.3] - 2019-07-xx
* Add `rustls` support
## [0.2.2] - 2019-07-01
### Changed

View file

@ -1,6 +1,6 @@
[package]
name = "awc"
version = "0.2.2"
version = "0.2.3"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix http client."
readme = "README.md"
@ -44,7 +44,7 @@ flate2-rust = ["actix-http/flate2-rust"]
[dependencies]
actix-codec = "0.1.2"
actix-service = "0.4.1"
actix-http = "0.2.4"
actix-http = "0.2.8"
base64 = "0.10.1"
bytes = "0.4"
derive_more = "0.15.0"

View file

@ -7,7 +7,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use actix_codec::{AsyncRead, AsyncWrite};
use actix_http::{HttpService, client::SslConnector::Rustls};
use actix_http::HttpService;
use actix_http_test::TestServer;
use actix_server::ssl::RustlsAcceptor;
use actix_service::{service_fn, NewService};
@ -74,7 +74,7 @@ fn test_connection_reuse_h2() {
.set_certificate_verifier(Arc::new(danger::NoCertificateVerification {}));
let client = awc::Client::build()
.connector(awc::Connector::new().ssl(Rustls(Arc::new(config))).finish())
.connector(awc::Connector::new().rustls(Arc::new(config)).finish())
.finish();
// req 1

View file

@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use actix_codec::{AsyncRead, AsyncWrite};
use actix_http::{HttpService, client::SslConnector::Openssl};
use actix_http::HttpService;
use actix_http_test::TestServer;
use actix_server::ssl::OpensslAcceptor;
use actix_service::{service_fn, NewService};
@ -67,7 +67,7 @@ fn test_connection_reuse_h2() {
.map_err(|e| log::error!("Can not set alpn protocol: {:?}", e));
let client = awc::Client::build()
.connector(awc::Connector::new().ssl(Openssl(builder.build())).finish())
.connector(awc::Connector::new().ssl(builder.build()).finish())
.finish();
// req 1

View file

@ -37,7 +37,7 @@ actix-rt = "0.2.4"
actix-service = "0.4.1"
actix-server = "0.6.0"
actix-utils = "0.4.1"
actix-http = "0.2.7"
actix-http = "0.2.8"
awc = "0.2.2"
base64 = "0.10"
@ -61,4 +61,3 @@ webpki = { version = "0.19", optional = true }
[dev-dependencies]
actix-web = "1.0.0"
actix-http = "0.2.7"

View file

@ -154,7 +154,6 @@ impl TestServer {
let connector = {
#[cfg(feature = "ssl")]
{
use actix_http::client::SslConnector::Openssl;
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
let mut builder =
@ -166,12 +165,11 @@ impl TestServer {
Connector::new()
.conn_lifetime(time::Duration::from_secs(0))
.timeout(time::Duration::from_millis(500))
.ssl(Openssl(builder.build()))
.ssl(builder.build())
.finish()
}
#[cfg(all(not(feature = "ssl"), feature = "rust-tls"))]
{
use actix_http::client::SslConnector::Rustls;
use rustls::ClientConfig;
use std::sync::Arc;
@ -185,7 +183,7 @@ impl TestServer {
Connector::new()
.conn_lifetime(time::Duration::from_secs(0))
.timeout(time::Duration::from_millis(500))
.ssl(Rustls(Arc::new(config)))
.rustls(Arc::new(config))
.finish()
}
#[cfg(not(any(feature = "ssl", feature = "rust-tls")))]

View file

@ -124,7 +124,6 @@ fn test_start_ssl() {
let client = test::run_on(|| {
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
use actix_http::client::SslConnector::Openssl;
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
builder.set_verify(SslVerifyMode::NONE);
let _ = builder
@ -135,7 +134,7 @@ fn test_start_ssl() {
awc::Client::build()
.connector(
awc::Connector::new()
.ssl(Openssl(builder.build()))
.ssl(builder.build())
.timeout(Duration::from_millis(100))
.finish(),
)

View file

@ -786,7 +786,6 @@ fn test_reading_deflate_encoding_large_random_ssl() {
use rustls::{NoClientAuth, ServerConfig};
use std::fs::File;
use std::io::BufReader;
use actix_http::client::SslConnector::Openssl;
let addr = TestServer::unused_addr();
let (tx, rx) = mpsc::channel();
@ -836,7 +835,7 @@ fn test_reading_deflate_encoding_large_random_ssl() {
.connector(
awc::Connector::new()
.timeout(std::time::Duration::from_millis(500))
.ssl(Openssl(builder.build()))
.ssl(builder.build())
.finish(),
)
.finish()