merge actix-connect

This commit is contained in:
Nikolay Kim 2020-03-25 10:43:20 +06:00
parent b59b625217
commit 243e274a82
32 changed files with 222 additions and 397 deletions

View file

@ -18,7 +18,6 @@ actix-service = { path = "actix-net/actix-service" }
actix-router = { path = "actix-net/router" }
actix-codec = { path = "actix-net/actix-codec" }
actix-connect = { path = "actix-net/actix-connect" }
actix-rt = { path = "actix-net/actix-rt" }
actix-macros = { path = "actix-net/actix-macros" }
bytestring = { path = "actix-net/string" }

View file

@ -1,116 +0,0 @@
# Changes
## [1.0.2] - 2020-01-15
* Fix actix-service 1.0.3 compatibility
## [1.0.1] - 2019-12-15
* Fix trust-dns-resolver compilation
## [1.0.0] - 2019-12-11
* Release
## [1.0.0-alpha.3] - 2019-12-07
### Changed
* Migrate to tokio 0.2
## [1.0.0-alpha.2] - 2019-12-02
### Changed
* Migrated to `std::future`
## [0.3.0] - 2019-10-03
### Changed
* Update `rustls` to 0.16
* Minimum required Rust version upped to 1.37.0
## [0.2.5] - 2019-09-05
* Add `TcpConnectService`
## [0.2.4] - 2019-09-02
* Use arbiter's storage for default async resolver
## [0.2.3] - 2019-08-05
* Add `ConnectService` and `OpensslConnectService`
## [0.2.2] - 2019-07-24
* Add `rustls` support
## [0.2.1] - 2019-07-17
### Added
* Expose Connect addrs #30
### Changed
* Update `derive_more` to 0.15
## [0.2.0] - 2019-05-12
### Changed
* Upgrade to actix-service 0.4
## [0.1.5] - 2019-04-19
### Added
* `Connect::set_addr()`
### Changed
* Use trust-dns-resolver 0.11.0
## [0.1.4] - 2019-04-12
### Changed
* Do not start default resolver immediately for default connector.
## [0.1.3] - 2019-04-11
### Changed
* Start trust-dns default resolver on first use
## [0.1.2] - 2019-04-04
### Added
* Log error if dns system config could not be loaded.
### Changed
* Rename connect Connector to TcpConnector #10
## [0.1.1] - 2019-03-15
### Fixed
* Fix error handling for single address
## [0.1.0] - 2019-03-14
* Refactor resolver and connector services
* Rename crate

View file

@ -1,57 +0,0 @@
[package]
name = "actix-connect"
version = "1.0.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix connect - tcp connector service"
keywords = ["network", "framework", "async", "futures"]
homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-net.git"
documentation = "https://docs.rs/actix-connect/"
categories = ["network-programming", "asynchronous"]
license = "MIT/Apache-2.0"
edition = "2018"
[package.metadata.docs.rs]
features = ["openssl", "rustls", "uri"]
[lib]
name = "actix_connect"
path = "src/lib.rs"
[features]
default = ["uri"]
# openssl
openssl = ["open-ssl", "tokio-openssl"]
# rustls
rustls = ["rust-tls", "tokio-rustls", "webpki"]
# support http::Uri as connect address
uri = ["http"]
[dependencies]
actix-service = "1.0.3"
actix-codec = "0.2.0"
actix-utils = "1.0.6"
actix-rt = "1.0.0"
derive_more = "0.99.2"
either = "1.5.3"
futures = "0.3.1"
http = { version = "0.2.0", optional = true }
log = "0.4"
trust-dns-proto = "=0.18.0-alpha.2"
trust-dns-resolver = "=0.18.0-alpha.2"
# openssl
open-ssl = { version="0.10", package = "openssl", optional = true }
tokio-openssl = { version = "0.4.0", optional = true }
# rustls
rust-tls = { version = "0.16.0", package = "rustls", optional = true }
tokio-rustls = { version = "0.12.0", optional = true }
webpki = { version = "0.21", optional = true }
[dev-dependencies]
bytes = "0.5.3"
actix-testing = { version="1.0.0" }

View file

@ -1 +0,0 @@
../LICENSE-APACHE

View file

@ -1 +0,0 @@
../LICENSE-MIT

View file

@ -1,7 +0,0 @@
//! SSL Services
#[cfg(feature = "openssl")]
pub mod openssl;
#[cfg(feature = "rustls")]
pub mod rustls;

View file

@ -1,137 +0,0 @@
use std::io;
use actix_codec::{BytesCodec, Framed};
use actix_rt::net::TcpStream;
use actix_service::{fn_service, Service, ServiceFactory};
use actix_testing::TestServer;
use bytes::Bytes;
use futures::SinkExt;
use actix_connect::resolver::{ResolverConfig, ResolverOpts};
use actix_connect::Connect;
#[cfg(feature = "openssl")]
#[actix_rt::test]
async fn test_string() {
let srv = TestServer::with(|| {
fn_service(|io: TcpStream| {
async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
}
})
});
let mut conn = actix_connect::default_connector();
let addr = format!("localhost:{}", srv.port());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "rustls")]
#[actix_rt::test]
async fn test_rustls_string() {
let srv = TestServer::with(|| {
fn_service(|io: TcpStream| {
async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
}
})
});
let mut conn = actix_connect::default_connector();
let addr = format!("localhost:{}", srv.port());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[actix_rt::test]
async fn test_static_str() {
let srv = TestServer::with(|| {
fn_service(|io: TcpStream| {
async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
}
})
});
let resolver = actix_connect::start_default_resolver();
let mut conn = actix_connect::new_connector(resolver.clone());
let con = conn.call(Connect::with("10", srv.addr())).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
let connect = Connect::new(srv.host().to_owned());
let mut conn = actix_connect::new_connector(resolver);
let con = conn.call(connect).await;
assert!(con.is_err());
}
#[actix_rt::test]
async fn test_new_service() {
let srv = TestServer::with(|| {
fn_service(|io: TcpStream| {
async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
}
})
});
let resolver =
actix_connect::start_resolver(ResolverConfig::default(), ResolverOpts::default());
let factory = actix_connect::new_connector_factory(resolver);
let mut conn = factory.new_service(()).await.unwrap();
let con = conn.call(Connect::with("10", srv.addr())).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "openssl")]
#[actix_rt::test]
async fn test_uri() {
use std::convert::TryFrom;
let srv = TestServer::with(|| {
fn_service(|io: TcpStream| {
async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
}
})
});
let mut conn = actix_connect::default_connector();
let addr = http::Uri::try_from(format!("https://localhost:{}", srv.port())).unwrap();
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "rustls")]
#[actix_rt::test]
async fn test_rustls_uri() {
use std::convert::TryFrom;
let srv = TestServer::with(|| {
fn_service(|io: TcpStream| {
async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
}
})
});
let mut conn = actix_connect::default_connector();
let addr = http::Uri::try_from(format!("https://localhost:{}", srv.port())).unwrap();
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}

View file

@ -41,7 +41,6 @@ ntex-service = { path = "../ntex-service" }
ntex-web-macros = { path = "../ntex-web-macros" }
actix-codec = "0.2.0"
actix-connect = "1.0.1"
actix-macros = "0.1.0"
actix-rt = "1.0.0"
actix-threadpool = "0.3.1"
@ -77,6 +76,8 @@ serde_urlencoded = "0.6.1"
url = "2.1"
time = { version = "0.2.5", default-features = false, features = ["std"] }
coo-kie = { version = "0.13.3", package = "cookie", optional = true }
trust-dns-proto = "=0.18.0-alpha.2"
trust-dns-resolver = "=0.18.0-alpha.2"
# openssl
open-ssl = { version="0.10", package = "openssl", optional = true }

View file

@ -16,7 +16,7 @@ async fn no_params() -> &'static str {
"Hello world!\r\n"
}
#[actix_rt::main]
#[ntex::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init();

View file

@ -7,7 +7,7 @@ use ntex::http::header::HeaderValue;
use ntex::http::{HttpService, Request, Response};
use ntex::server::Server;
#[actix_rt::main]
#[ntex::main]
async fn main() -> io::Result<()> {
env::set_var("RUST_LOG", "echo=info");
env_logger::init();

View file

@ -19,7 +19,7 @@ async fn handle_request(mut req: Request) -> Result<Response, io::Error> {
.body(body))
}
#[actix_rt::main]
#[ntex::main]
async fn main() -> io::Result<()> {
env::set_var("RUST_LOG", "echo=info");
env_logger::init();

View file

@ -6,7 +6,7 @@ use ntex::http::header::HeaderValue;
use ntex::http::{HttpService, Response};
use ntex::server::Server;
#[actix_rt::main]
#[ntex::main]
async fn main() -> io::Result<()> {
env::set_var("RUST_LOG", "hello_world=info");
env_logger::init();

View file

@ -19,7 +19,7 @@ async fn no_params() -> &'static str {
}
#[cfg(unix)]
#[actix_rt::main]
#[ntex::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init();

View file

@ -6,10 +6,11 @@ use std::net::SocketAddr;
use std::pin::Pin;
use std::task::{Context, Poll};
use actix_rt::net::TcpStream;
use actix_service::{Service, ServiceFactory};
use futures::future::{err, ok, BoxFuture, Either, FutureExt, Ready};
use crate::rt::net::TcpStream;
use crate::service::{Service, ServiceFactory};
use super::connect::{Address, Connect, Connection};
use super::error::ConnectError;
@ -74,7 +75,8 @@ impl<T: Address> Service for TcpConnector<T> {
type Request = Connect<T>;
type Response = Connection<T, TcpStream>;
type Error = ConnectError;
type Future = Either<TcpConnectorResponse<T>, Ready<Result<Self::Response, Self::Error>>>;
type Future =
Either<TcpConnectorResponse<T>, Ready<Result<Self::Response, Self::Error>>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
@ -156,7 +158,9 @@ impl<T: Address> Future for TcpConnectorResponse<T> {
this.req.as_ref().unwrap().host(),
this.port,
);
if this.addrs.is_none() || this.addrs.as_ref().unwrap().is_empty() {
if this.addrs.is_none()
|| this.addrs.as_ref().unwrap().is_empty()
{
return Poll::Ready(Err(err.into()));
}
}

View file

@ -4,25 +4,20 @@
//!
//! * `openssl` - enables ssl support via `openssl` crate
//! * `rustls` - enables ssl support via `rustls` crate
#![deny(rust_2018_idioms, warnings)]
#![allow(clippy::type_complexity)]
#![recursion_limit = "128"]
#[macro_use]
extern crate log;
mod connect;
mod connector;
mod error;
mod resolve;
mod service;
pub mod ssl;
#[cfg(feature = "uri")]
mod uri;
use actix_rt::{net::TcpStream, Arbiter};
use actix_service::{pipeline, pipeline_factory, Service, ServiceFactory};
#[cfg(feature = "openssl")]
pub mod openssl;
#[cfg(feature = "rustls")]
pub mod rustls;
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
use trust_dns_resolver::system_conf::read_system_conf;
use trust_dns_resolver::AsyncResolver;
@ -33,6 +28,9 @@ pub mod resolver {
pub use trust_dns_resolver::{error::ResolveError, AsyncResolver};
}
use crate::rt::{net::TcpStream, Arbiter};
use crate::service::{pipeline, pipeline_factory, Service, ServiceFactory};
pub use self::connect::{Address, Connect, Connection};
pub use self::connector::{TcpConnector, TcpConnectorFactory};
pub use self::error::ConnectError;
@ -74,8 +72,11 @@ pub fn start_default_resolver() -> AsyncResolver {
/// Create tcp connector service
pub fn new_connector<T: Address + 'static>(
resolver: AsyncResolver,
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
+ Clone {
) -> impl Service<
Request = Connect<T>,
Response = Connection<T, TcpStream>,
Error = ConnectError,
> + Clone {
pipeline(Resolver::new(resolver)).and_then(TcpConnector::new())
}
@ -93,9 +94,11 @@ pub fn new_connector_factory<T: Address + 'static>(
}
/// Create connector service with default parameters
pub fn default_connector<T: Address + 'static>(
) -> impl Service<Request = Connect<T>, Response = Connection<T, TcpStream>, Error = ConnectError>
+ Clone {
pub fn default_connector<T: Address + 'static>() -> impl Service<
Request = Connect<T>,
Response = Connection<T, TcpStream>,
Error = ConnectError,
> + Clone {
pipeline(Resolver::default()).and_then(TcpConnector::new())
}

View file

@ -8,14 +8,14 @@ pub use open_ssl::ssl::{Error as SslError, SslConnector, SslMethod};
pub use tokio_openssl::{HandshakeError, SslStream};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_rt::net::TcpStream;
use actix_service::{Service, ServiceFactory};
use futures::future::{err, ok, Either, FutureExt, LocalBoxFuture, Ready};
use trust_dns_resolver::AsyncResolver;
use crate::{
use crate::connect::{
Address, Connect, ConnectError, ConnectService, ConnectServiceFactory, Connection,
};
use crate::rt::net::TcpStream;
use crate::service::{Service, ServiceFactory};
/// Openssl connector factory
pub struct OpensslConnector<T, U> {
@ -97,7 +97,8 @@ where
type Request = Connection<T, U>;
type Response = Connection<T, SslStream<U>>;
type Error = io::Error;
type Future = Either<ConnectAsyncExt<T, U>, Ready<Result<Self::Response, Self::Error>>>;
type Future =
Either<ConnectAsyncExt<T, U>, Ready<Result<Self::Response, Self::Error>>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))

View file

@ -4,14 +4,15 @@ use std::net::SocketAddr;
use std::pin::Pin;
use std::task::{Context, Poll};
use actix_service::{Service, ServiceFactory};
use futures::future::{ok, Either, Ready};
use trust_dns_resolver::lookup_ip::LookupIpFuture;
use trust_dns_resolver::{AsyncResolver, Background};
use crate::connect::{Address, Connect};
use crate::error::ConnectError;
use crate::get_default_resolver;
use crate::service::{Service, ServiceFactory};
use super::connect::{Address, Connect};
use super::error::ConnectError;
use super::get_default_resolver;
/// DNS Resolver Service factory
pub struct ResolverFactory<T> {

View file

@ -9,12 +9,12 @@ pub use rust_tls::Session;
pub use tokio_rustls::{client::TlsStream, rustls::ClientConfig};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_service::{Service, ServiceFactory};
use futures::future::{ok, Ready};
use tokio_rustls::{Connect, TlsConnector};
use webpki::DNSNameRef;
use crate::{Address, Connection};
use crate::connect::{Address, Connection};
use crate::service::{Service, ServiceFactory};
/// Rustls connector factory
pub struct RustlsConnector<T, U> {

View file

@ -2,16 +2,17 @@ use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use actix_rt::net::TcpStream;
use actix_service::{Service, ServiceFactory};
use either::Either;
use futures::future::{ok, Ready};
use trust_dns_resolver::AsyncResolver;
use crate::connect::{Address, Connect, Connection};
use crate::connector::{TcpConnector, TcpConnectorFactory};
use crate::error::ConnectError;
use crate::resolve::{Resolver, ResolverFactory};
use crate::rt::net::TcpStream;
use crate::service::{Service, ServiceFactory};
use super::connect::{Address, Connect, Connection};
use super::connector::{TcpConnector, TcpConnectorFactory};
use super::error::ConnectError;
use super::resolve::{Resolver, ResolverFactory};
pub struct ConnectServiceFactory<T> {
tcp: TcpConnectorFactory<T>,

View file

@ -1,6 +1,6 @@
use http::Uri;
use crate::http::Uri;
use crate::Address;
use super::Address;
impl Address for Uri {
fn host(&self) -> &str {

View file

@ -525,7 +525,7 @@ mod tests {
}
}
#[actix_rt::test]
#[crate::test]
async fn test_static_str() {
assert_eq!(Body::from("").size(), BodySize::Sized(0));
assert_eq!(Body::from("test").size(), BodySize::Sized(4));
@ -538,7 +538,7 @@ mod tests {
);
}
#[actix_rt::test]
#[crate::test]
async fn test_static_bytes() {
assert_eq!(Body::from(b"test".as_ref()).size(), BodySize::Sized(4));
assert_eq!(Body::from(b"test".as_ref()).get_ref(), b"test");
@ -558,7 +558,7 @@ mod tests {
);
}
#[actix_rt::test]
#[crate::test]
async fn test_vec() {
assert_eq!(Body::from(Vec::from("test")).size(), BodySize::Sized(4));
assert_eq!(Body::from(Vec::from("test")).get_ref(), b"test");

View file

@ -3,12 +3,12 @@ use std::marker::PhantomData;
use std::time::Duration;
use actix_codec::{AsyncRead, AsyncWrite};
use actix_connect::{
use crate::connect::{
default_connector, Connect as TcpConnect, Connection as TcpConnection,
};
use actix_rt::net::TcpStream;
use crate::http::{Protocol, Uri};
use crate::rt::net::TcpStream;
use crate::util::timeout::{TimeoutError, TimeoutService};
use crate::{apply_fn, Service};
@ -18,10 +18,10 @@ use super::pool::ConnectionPool;
use super::Connect;
#[cfg(feature = "openssl")]
use actix_connect::ssl::openssl::SslConnector as OpensslConnector;
use crate::connect::openssl::SslConnector as OpensslConnector;
#[cfg(feature = "rustls")]
use actix_connect::ssl::rustls::ClientConfig;
use crate::connect::rustls::ClientConfig;
#[cfg(feature = "rustls")]
use std::sync::Arc;
@ -69,14 +69,14 @@ impl Connector<(), ()> {
impl Service<
Request = TcpConnect<Uri>,
Response = TcpConnection<Uri, TcpStream>,
Error = actix_connect::ConnectError,
Error = crate::connect::ConnectError,
> + Clone,
TcpStream,
> {
let ssl = {
#[cfg(feature = "openssl")]
{
use actix_connect::ssl::openssl::SslMethod;
use crate::connect::openssl::SslMethod;
let mut ssl = OpensslConnector::builder(SslMethod::tls()).unwrap();
let _ = ssl
@ -119,7 +119,7 @@ impl<T, U> Connector<T, U> {
T1: Service<
Request = TcpConnect<Uri>,
Response = TcpConnection<Uri, U1>,
Error = actix_connect::ConnectError,
Error = crate::connect::ConnectError,
> + Clone,
{
Connector {
@ -141,7 +141,7 @@ where
T: Service<
Request = TcpConnect<Uri>,
Response = TcpConnection<Uri, U>,
Error = actix_connect::ConnectError,
Error = crate::connect::ConnectError,
> + Clone
+ 'static,
{
@ -243,11 +243,11 @@ where
#[cfg(any(feature = "openssl", feature = "rustls"))]
{
const H2: &[u8] = b"h2";
use crate::{boxed::service, pipeline};
#[cfg(feature = "openssl")]
use actix_connect::ssl::openssl::OpensslConnector;
use crate::connect::openssl::OpensslConnector;
#[cfg(feature = "rustls")]
use actix_connect::ssl::rustls::{RustlsConnector, Session};
use crate::connect::rustls::{RustlsConnector, Session};
use crate::{boxed::service, pipeline};
let ssl_service = TimeoutService::new(
self.timeout,

View file

@ -2,12 +2,12 @@
use std::error::Error;
use std::io;
use actix_connect::resolver::ResolveError;
use derive_more::{Display, From};
use serde_json::error::Error as JsonError;
#[cfg(feature = "openssl")]
use actix_connect::ssl::openssl::{HandshakeError, SslError};
use crate::connect::openssl::{HandshakeError, SslError};
use crate::connect::resolver::ResolveError;
use crate::http::error::{HttpError, ParseError, PayloadError};
use crate::http::header::HeaderValue;
@ -121,14 +121,14 @@ pub enum ConnectError {
impl std::error::Error for ConnectError {}
impl From<actix_connect::ConnectError> for ConnectError {
fn from(err: actix_connect::ConnectError) -> ConnectError {
impl From<crate::connect::ConnectError> for ConnectError {
fn from(err: crate::connect::ConnectError) -> ConnectError {
match err {
actix_connect::ConnectError::Resolver(e) => ConnectError::Resolver(e),
actix_connect::ConnectError::NoRecords => ConnectError::NoRecords,
actix_connect::ConnectError::InvalidInput => panic!(),
actix_connect::ConnectError::Unresolverd => ConnectError::Unresolverd,
actix_connect::ConnectError::Io(e) => ConnectError::Io(e),
crate::connect::ConnectError::Resolver(e) => ConnectError::Resolver(e),
crate::connect::ConnectError::NoRecords => ConnectError::NoRecords,
crate::connect::ConnectError::InvalidInput => panic!(),
crate::connect::ConnectError::Unresolverd => ConnectError::Unresolverd,
crate::connect::ConnectError::Io(e) => ConnectError::Io(e),
}
}
}

View file

@ -8,13 +8,13 @@ use std::task::{Context, Poll};
use std::{net, thread, time};
use actix_codec::{AsyncRead, AsyncWrite, Framed};
use actix_rt::{net::TcpStream, System};
use bytes::{Bytes, BytesMut};
use futures::Stream;
#[cfg(feature = "cookie")]
use coo_kie::{Cookie, CookieJar};
use crate::rt::{net::TcpStream, System};
use crate::server::{Server, ServiceFactory};
use super::client::error::WsClientError;
@ -351,7 +351,7 @@ pub fn server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer {
Client::build().connector(connector).finish()
};
actix_connect::start_default_resolver();
crate::connect::start_default_resolver();
TestServer {
addr,

View file

@ -15,13 +15,14 @@
#[macro_use]
extern crate log;
#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub use actix_macros::{main, test};
pub mod channel;
pub mod connect;
pub mod framed;
pub mod http;
pub mod router;
pub mod rt;
pub mod server;
pub mod service;
pub mod task;

2
ntex/src/rt.rs Normal file
View file

@ -0,0 +1,2 @@
//! A runtime implementation that runs everything on the current thread.
pub use actix_rt::*;

View file

@ -96,7 +96,7 @@ impl WebResponseError<DefaultError> for FormError {}
#[cfg(feature = "openssl")]
/// `InternalServerError` for `openssl::ssl::Error`
impl WebResponseError<DefaultError> for actix_connect::ssl::openssl::SslError {}
impl WebResponseError<DefaultError> for crate::connect::openssl::SslError {}
#[cfg(feature = "openssl")]
/// `InternalServerError` for `openssl::ssl::HandshakeError`

131
ntex/tests/connect.rs Normal file
View file

@ -0,0 +1,131 @@
use std::io;
use actix_codec::{BytesCodec, Framed};
use bytes::Bytes;
use futures::SinkExt;
use ntex::connect::resolver::{ResolverConfig, ResolverOpts};
use ntex::connect::Connect;
use ntex::rt::net::TcpStream;
use ntex::server::test_server;
use ntex::service::{fn_service, Service, ServiceFactory};
#[cfg(feature = "openssl")]
#[ntex::test]
async fn test_string() {
let srv = test_server(|| {
fn_service(|io: TcpStream| async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
})
});
let mut conn = ntex::connect::default_connector();
let addr = format!("localhost:{}", srv.addr().port());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "rustls")]
#[ntex::test]
async fn test_rustls_string() {
let srv = test_server(|| {
fn_service(|io: TcpStream| async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
})
});
let mut conn = ntex::connect::default_connector();
let addr = format!("localhost:{}", srv.addr().port());
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[ntex::test]
async fn test_static_str() {
let srv = test_server(|| {
fn_service(|io: TcpStream| async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
})
});
let resolver = ntex::connect::start_default_resolver();
let mut conn = ntex::connect::new_connector(resolver.clone());
let con = conn.call(Connect::with("10", srv.addr())).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
let connect = Connect::new("127.0.0.1".to_owned());
let mut conn = ntex::connect::new_connector(resolver);
let con = conn.call(connect).await;
assert!(con.is_err());
}
#[ntex::test]
async fn test_new_service() {
let srv = test_server(|| {
fn_service(|io: TcpStream| async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
})
});
let resolver = ntex::connect::start_resolver(
ResolverConfig::default(),
ResolverOpts::default(),
);
let factory = ntex::connect::new_connector_factory(resolver);
let mut conn = factory.new_service(()).await.unwrap();
let con = conn.call(Connect::with("10", srv.addr())).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "openssl")]
#[ntex::test]
async fn test_uri() {
use std::convert::TryFrom;
let srv = test_server(|| {
fn_service(|io: TcpStream| async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
})
});
let mut conn = ntex::connect::default_connector();
let addr =
ntex::http::Uri::try_from(format!("https://localhost:{}", srv.addr().port()))
.unwrap();
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}
#[cfg(feature = "rustls")]
#[ntex::test]
async fn test_rustls_uri() {
use std::convert::TryFrom;
let srv = test_server(|| {
fn_service(|io: TcpStream| async {
let mut framed = Framed::new(io, BytesCodec);
framed.send(Bytes::from_static(b"test")).await?;
Ok::<_, io::Error>(())
})
});
let mut conn = ntex::connect::default_connector();
let addr =
ntex::http::Uri::try_from(format!("https://localhost:{}", srv.addr().port()))
.unwrap();
let con = conn.call(addr.into()).await.unwrap();
assert_eq!(con.peer_addr().unwrap(), srv.addr());
}

View file

@ -13,7 +13,7 @@ use ntex::{fn_factory_with_config, fn_service, IntoService, Service};
#[derive(Clone)]
struct State(Option<mpsc::Sender<Bytes>>);
#[actix_rt::test]
#[ntex::test]
async fn test_basic() {
let client_item = Rc::new(Cell::new(false));
@ -43,8 +43,8 @@ async fn test_basic() {
.into_service())
}));
let conn = actix_connect::default_connector()
.call(actix_connect::Connect::with(String::new(), srv.addr()))
let conn = ntex::connect::default_connector()
.call(ntex::connect::Connect::with(String::new(), srv.addr()))
.await
.unwrap();

View file

@ -113,8 +113,8 @@ async fn test_timeout() {
});
let connector = Connector::new()
.connector(actix_connect::new_connector(
actix_connect::start_default_resolver(),
.connector(ntex::connect::new_connector(
ntex::connect::start_default_resolver(),
))
.timeout(Duration::from_secs(15))
.finish();