mirror of
https://github.com/actix/actix-extras.git
synced 2025-07-01 12:15:08 +02:00
use new actix crates
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
use actix_net::connector::RequestPort;
|
||||
use actix_net::resolver::RequestHost;
|
||||
use actix_connector::{RequestHost, RequestPort};
|
||||
use http::uri::Uri;
|
||||
use http::{Error as HttpError, HttpTryFrom};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{fmt, io, time};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use futures::Poll;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::pool::Acquired;
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
use std::time::Duration;
|
||||
use std::{fmt, io};
|
||||
|
||||
use actix_net::connector::TcpConnector;
|
||||
use actix_net::resolver::Resolver;
|
||||
use actix_net::service::{Service, ServiceExt};
|
||||
use actix_net::timeout::{TimeoutError, TimeoutService};
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use actix_connector::{Resolver, TcpConnector};
|
||||
use actix_service::Service;
|
||||
use actix_utils::timeout::{TimeoutError, TimeoutService};
|
||||
use futures::future::Either;
|
||||
use futures::Poll;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
||||
|
||||
use super::connect::Connect;
|
||||
@ -16,7 +15,7 @@ use super::error::ConnectorError;
|
||||
use super::pool::ConnectionPool;
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
use actix_net::ssl::OpensslConnector;
|
||||
use actix_connector::ssl::OpensslConnector;
|
||||
#[cfg(feature = "ssl")]
|
||||
use openssl::ssl::{SslConnector, SslMethod};
|
||||
|
||||
@ -169,7 +168,7 @@ impl Connector {
|
||||
.and_then(TcpConnector::default().from_err())
|
||||
.and_then(
|
||||
OpensslConnector::service(self.connector)
|
||||
.map_err(ConnectorError::SslError),
|
||||
.map_err(ConnectorError::from),
|
||||
),
|
||||
)
|
||||
.map_err(|e| match e {
|
||||
|
@ -4,13 +4,7 @@ use failure::Fail;
|
||||
use trust_dns_resolver::error::ResolveError;
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
use openssl::ssl::Error as SslError;
|
||||
|
||||
#[cfg(all(feature = "tls", not(any(feature = "ssl", feature = "rust-tls"))))]
|
||||
use native_tls::Error as SslError;
|
||||
|
||||
#[cfg(all(feature = "rust-tls", not(any(feature = "tls", feature = "ssl"))))]
|
||||
use std::io::Error as SslError;
|
||||
use openssl::ssl::{Error as SslError, HandshakeError};
|
||||
|
||||
use crate::error::{Error, ParseError};
|
||||
|
||||
@ -26,7 +20,7 @@ pub enum ConnectorError {
|
||||
SslIsNotSupported,
|
||||
|
||||
/// SSL error
|
||||
#[cfg(any(feature = "tls", feature = "ssl", feature = "rust-tls"))]
|
||||
#[cfg(feature = "ssl")]
|
||||
#[fail(display = "{}", _0)]
|
||||
SslError(#[cause] SslError),
|
||||
|
||||
@ -73,6 +67,28 @@ impl From<ResolveError> for ConnectorError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
impl From<SslError> for ConnectorError {
|
||||
fn from(err: SslError) -> ConnectorError {
|
||||
ConnectorError::SslError(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ssl")]
|
||||
impl<T> From<HandshakeError<T>> for ConnectorError {
|
||||
fn from(err: HandshakeError<T>) -> ConnectorError {
|
||||
match err {
|
||||
HandshakeError::SetupFailure(stack) => SslError::from(stack).into(),
|
||||
HandshakeError::Failure(stream) => {
|
||||
SslError::from(stream.into_error()).into()
|
||||
}
|
||||
HandshakeError::WouldBlock(stream) => {
|
||||
SslError::from(stream.into_error()).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of errors that can occur during request sending and response reading
|
||||
#[derive(Debug)]
|
||||
pub enum SendRequestError {
|
||||
|
@ -1,11 +1,10 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::Service;
|
||||
use bytes::Bytes;
|
||||
use futures::future::{err, ok, Either};
|
||||
use futures::{Async, Future, Poll, Sink, Stream};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::error::{ConnectorError, SendRequestError};
|
||||
use super::response::ClientResponse;
|
||||
|
@ -4,7 +4,9 @@ use std::io;
|
||||
use std::rc::Rc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use actix_rt::spawn;
|
||||
use actix_service::Service;
|
||||
use futures::future::{ok, Either, FutureResult};
|
||||
use futures::sync::oneshot;
|
||||
use futures::task::AtomicTask;
|
||||
@ -12,8 +14,6 @@ use futures::{Async, Future, Poll};
|
||||
use http::uri::Authority;
|
||||
use indexmap::IndexSet;
|
||||
use slab::Slab;
|
||||
use tokio_current_thread::spawn;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::{sleep, Delay};
|
||||
|
||||
use super::connect::Connect;
|
||||
|
@ -2,7 +2,7 @@ use std::fmt;
|
||||
use std::fmt::Write as FmtWrite;
|
||||
use std::io::Write;
|
||||
|
||||
use actix_net::service::Service;
|
||||
use actix_service::Service;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use cookie::{Cookie, CookieJar};
|
||||
use futures::{Future, Stream};
|
||||
@ -23,26 +23,24 @@ use super::{pipeline, Connect, Connection, ConnectorError, SendRequestError};
|
||||
/// An HTTP Client Request
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate actix_web;
|
||||
/// # extern crate futures;
|
||||
/// # extern crate tokio;
|
||||
/// # use futures::Future;
|
||||
/// # use std::process;
|
||||
/// use actix_web::{actix, client};
|
||||
/// use futures::future::{Future, lazy};
|
||||
/// use actix_rt::System;
|
||||
/// use actix_http::client;
|
||||
///
|
||||
/// fn main() {
|
||||
/// actix::run(
|
||||
/// || client::ClientRequest::get("http://www.rust-lang.org") // <- Create request builder
|
||||
/// .header("User-Agent", "Actix-web")
|
||||
/// .finish().unwrap()
|
||||
/// .send() // <- Send http request
|
||||
/// .map_err(|_| ())
|
||||
/// .and_then(|response| { // <- server http response
|
||||
/// println!("Response: {:?}", response);
|
||||
/// # actix::System::current().stop();
|
||||
/// Ok(())
|
||||
/// }),
|
||||
/// );
|
||||
/// System::new("test").block_on(lazy(|| {
|
||||
/// let mut connector = client::Connector::default().service();
|
||||
/// client::ClientRequest::get("http://www.rust-lang.org") // <- Create request builder
|
||||
/// .header("User-Agent", "Actix-web")
|
||||
/// .finish().unwrap()
|
||||
/// .send(&mut connector) // <- Send http request
|
||||
/// .map_err(|_| ())
|
||||
/// .and_then(|response| { // <- server http response
|
||||
/// println!("Response: {:?}", response);
|
||||
/// # actix_rt::System::current().stop();
|
||||
/// Ok(())
|
||||
/// })
|
||||
/// }));
|
||||
/// }
|
||||
/// ```
|
||||
pub struct ClientRequest<B: MessageBody = ()> {
|
||||
|
@ -4,11 +4,11 @@ use std::rc::Rc;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{fmt, net};
|
||||
|
||||
use actix_rt::spawn;
|
||||
use bytes::BytesMut;
|
||||
use futures::{future, Future};
|
||||
use log::error;
|
||||
use time;
|
||||
use tokio_current_thread::spawn;
|
||||
use tokio_timer::{sleep, Delay};
|
||||
|
||||
// "Sun, 06 Nov 1994 08:49:37 GMT".len()
|
||||
@ -378,8 +378,8 @@ impl DateService {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_rt::System;
|
||||
use futures::future;
|
||||
use tokio::runtime::current_thread;
|
||||
|
||||
#[test]
|
||||
fn test_date_len() {
|
||||
@ -388,7 +388,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_date() {
|
||||
let mut rt = current_thread::Runtime::new().unwrap();
|
||||
let mut rt = System::new("test");
|
||||
|
||||
let _ = rt.block_on(future::lazy(|| {
|
||||
let settings = ServiceConfig::new(KeepAlive::Os, 0, 0);
|
||||
|
@ -5,7 +5,7 @@ use std::string::FromUtf8Error;
|
||||
use std::sync::Mutex;
|
||||
use std::{fmt, io, result};
|
||||
|
||||
use actix::MailboxError;
|
||||
// use actix::MailboxError;
|
||||
use cookie;
|
||||
use failure::{self, Backtrace, Fail};
|
||||
use futures::Canceled;
|
||||
@ -250,8 +250,8 @@ impl ResponseError for header::InvalidHeaderValueBytes {
|
||||
/// `InternalServerError` for `futures::Canceled`
|
||||
impl ResponseError for Canceled {}
|
||||
|
||||
/// `InternalServerError` for `actix::MailboxError`
|
||||
impl ResponseError for MailboxError {}
|
||||
// /// `InternalServerError` for `actix::MailboxError`
|
||||
// impl ResponseError for MailboxError {}
|
||||
|
||||
/// A set of errors that can occur during parsing HTTP streams
|
||||
#[derive(Fail, Debug)]
|
||||
|
@ -1,13 +1,13 @@
|
||||
#![allow(unused_imports, unused_variables, dead_code)]
|
||||
use std::io::{self, Write};
|
||||
|
||||
use actix_codec::{Decoder, Encoder};
|
||||
use bitflags::bitflags;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use http::header::{
|
||||
HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING, UPGRADE,
|
||||
};
|
||||
use http::{Method, Version};
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
|
||||
use super::decoder::{PayloadDecoder, PayloadItem, PayloadType};
|
||||
use super::{decoder, encoder};
|
||||
|
@ -2,11 +2,11 @@
|
||||
use std::fmt;
|
||||
use std::io::{self, Write};
|
||||
|
||||
use actix_codec::{Decoder, Encoder};
|
||||
use bitflags::bitflags;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
|
||||
use http::{Method, StatusCode, Version};
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
|
||||
use super::decoder::{PayloadDecoder, PayloadItem, PayloadType};
|
||||
use super::{decoder, encoder};
|
||||
@ -192,9 +192,9 @@ impl Encoder for Codec {
|
||||
mod tests {
|
||||
use std::{cmp, io};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use bytes::{Buf, Bytes, BytesMut};
|
||||
use http::{Method, Version};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::*;
|
||||
use crate::error::ParseError;
|
||||
|
@ -1,13 +1,13 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::{io, mem};
|
||||
|
||||
use actix_codec::Decoder;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures::{Async, Poll};
|
||||
use http::header::{HeaderName, HeaderValue};
|
||||
use http::{header, HeaderMap, HttpTryFrom, Method, StatusCode, Uri, Version};
|
||||
use httparse;
|
||||
use log::{debug, error, trace};
|
||||
use tokio_codec::Decoder;
|
||||
|
||||
use crate::client::ClientResponse;
|
||||
use crate::error::ParseError;
|
||||
@ -607,9 +607,9 @@ impl ChunkedState {
|
||||
mod tests {
|
||||
use std::{cmp, io};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite};
|
||||
use bytes::{Buf, Bytes, BytesMut};
|
||||
use http::{Method, Version};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::*;
|
||||
use crate::error::ParseError;
|
||||
|
@ -3,12 +3,11 @@ use std::fmt::Debug;
|
||||
use std::mem;
|
||||
use std::time::Instant;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::Service;
|
||||
use bitflags::bitflags;
|
||||
use futures::{try_ready, Async, Future, Poll, Sink, Stream};
|
||||
use log::{debug, error, trace};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::Delay;
|
||||
|
||||
use crate::body::{Body, BodyLength, MessageBody, ResponseBody};
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! HTTP/1 implementation
|
||||
use std::fmt;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_codec::Framed;
|
||||
use bytes::Bytes;
|
||||
|
||||
mod client;
|
||||
|
@ -2,12 +2,11 @@ use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
use std::net;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::{IntoNewService, NewService, Service};
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::{IntoNewService, NewService, Service};
|
||||
use futures::future::{ok, FutureResult};
|
||||
use futures::{try_ready, Async, Future, Poll, Stream};
|
||||
use log::error;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::MessageBody;
|
||||
use crate::config::{KeepAlive, ServiceConfig};
|
||||
|
@ -523,8 +523,8 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_rt::Runtime;
|
||||
use futures::future::{lazy, result};
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
|
||||
#[test]
|
||||
fn test_error() {
|
||||
|
@ -1,10 +1,9 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::{NewService, Service};
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::{NewService, Service};
|
||||
use futures::future::{ok, Either, FutureResult};
|
||||
use futures::{Async, Future, Poll, Sink};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::{BodyLength, MessageBody, ResponseBody};
|
||||
use crate::error::{Error, ResponseError};
|
||||
|
16
src/test.rs
16
src/test.rs
@ -3,10 +3,10 @@ use std::str::FromStr;
|
||||
use std::sync::mpsc;
|
||||
use std::{net, thread};
|
||||
|
||||
use actix::System;
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::server::{Server, StreamServiceFactory};
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_rt::{Runtime, System};
|
||||
use actix_server::{Server, StreamServiceFactory};
|
||||
use actix_service::Service;
|
||||
|
||||
use bytes::Bytes;
|
||||
use cookie::Cookie;
|
||||
@ -14,8 +14,6 @@ use futures::future::{lazy, Future};
|
||||
use http::header::HeaderName;
|
||||
use http::{HeaderMap, HttpTryFrom, Method, Uri, Version};
|
||||
use net2::TcpBuilder;
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::MessageBody;
|
||||
use crate::client::{
|
||||
@ -316,7 +314,7 @@ impl TestServer {
|
||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let local_addr = tcp.local_addr().unwrap();
|
||||
|
||||
Server::default()
|
||||
Server::build()
|
||||
.listen("test", tcp, factory)
|
||||
.workers(1)
|
||||
.disable_signals()
|
||||
@ -390,9 +388,9 @@ impl<T> TestServerRuntime<T> {
|
||||
/// Construct test server url
|
||||
pub fn url(&self, uri: &str) -> String {
|
||||
if uri.starts_with('/') {
|
||||
format!("http://localhost:{}{}", self.addr.port(), uri)
|
||||
format!("http://127.0.0.1:{}{}", self.addr.port(), uri)
|
||||
} else {
|
||||
format!("http://localhost:{}/{}", self.addr.port(), uri)
|
||||
format!("http://127.0.0.1:{}/{}", self.addr.port(), uri)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Http client request
|
||||
use std::io;
|
||||
|
||||
use actix_net::connector::ConnectorError;
|
||||
use actix_connector::ConnectorError;
|
||||
use failure::Fail;
|
||||
use http::{header::HeaderValue, Error as HttpError, StatusCode};
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! websockets client
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::connector::{Connect as TcpConnect, ConnectorError, DefaultConnector};
|
||||
use actix_net::service::Service;
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_connector::{Connect as TcpConnect, ConnectorError, DefaultConnector};
|
||||
use actix_service::Service;
|
||||
use base64;
|
||||
use futures::future::{err, Either, FutureResult};
|
||||
use futures::{try_ready, Async, Future, Poll, Sink, Stream};
|
||||
@ -12,7 +12,6 @@ use http::{HttpTryFrom, StatusCode};
|
||||
use log::trace;
|
||||
use rand;
|
||||
use sha1::Sha1;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::body::BodyLength;
|
||||
use crate::client::ClientResponse;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use actix_codec::{Decoder, Encoder};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
|
||||
use super::frame::Parser;
|
||||
use super::proto::{CloseReason, OpCode};
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::service::{NewService, Service};
|
||||
use actix_codec::Framed;
|
||||
use actix_service::{NewService, Service};
|
||||
use futures::future::{ok, FutureResult};
|
||||
use futures::{Async, IntoFuture, Poll};
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
use actix_net::codec::Framed;
|
||||
use actix_net::framed::{FramedTransport, FramedTransportError};
|
||||
use actix_net::service::{IntoService, Service};
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_service::{IntoService, Service};
|
||||
use actix_utils::framed::{FramedTransport, FramedTransportError};
|
||||
use futures::{Future, Poll};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::{Codec, Frame, Message};
|
||||
|
||||
|
Reference in New Issue
Block a user