mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-26 06:57:43 +02:00
apply standard formatting
This commit is contained in:
@ -4,11 +4,10 @@ use std::{
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use actix_http::body::{BodySize, BoxBody, MessageBody};
|
||||
use bytes::Bytes;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
use actix_http::body::{BodySize, BoxBody, MessageBody};
|
||||
|
||||
pin_project! {
|
||||
/// Represents various types of HTTP message body.
|
||||
#[derive(Clone)]
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::{fmt, net::IpAddr, rc::Rc, time::Duration};
|
||||
|
||||
use base64::prelude::*;
|
||||
|
||||
use actix_http::{
|
||||
error::HttpError,
|
||||
header::{self, HeaderMap, HeaderName, TryIntoHeaderPair},
|
||||
@ -9,6 +7,7 @@ use actix_http::{
|
||||
};
|
||||
use actix_rt::net::{ActixStream, TcpStream};
|
||||
use actix_service::{boxed, Service};
|
||||
use base64::prelude::*;
|
||||
|
||||
use crate::{
|
||||
client::{
|
||||
@ -72,11 +71,8 @@ where
|
||||
/// Use custom connector service.
|
||||
pub fn connector<S1, Io1>(self, connector: Connector<S1>) -> ClientBuilder<S1, M>
|
||||
where
|
||||
S1: Service<
|
||||
ConnectInfo<Uri>,
|
||||
Response = TcpConnection<Uri, Io1>,
|
||||
Error = TcpConnectError,
|
||||
> + Clone
|
||||
S1: Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, Io1>, Error = TcpConnectError>
|
||||
+ Clone
|
||||
+ 'static,
|
||||
Io1: ActixStream + fmt::Debug + 'static,
|
||||
{
|
||||
@ -227,10 +223,7 @@ where
|
||||
/// Registers middleware, in the form of a middleware component (type), that runs during inbound
|
||||
/// and/or outbound processing in the request life-cycle (request -> response),
|
||||
/// modifying request/response as necessary, across all requests managed by the `Client`.
|
||||
pub fn wrap<S1, M1>(
|
||||
self,
|
||||
mw: M1,
|
||||
) -> ClientBuilder<S, NestTransform<M, M1, S1, ConnectRequest>>
|
||||
pub fn wrap<S1, M1>(self, mw: M1) -> ClientBuilder<S, NestTransform<M, M1, S1, ConnectRequest>>
|
||||
where
|
||||
M: Transform<S1, ConnectRequest>,
|
||||
M1: Transform<M::Transform, ConnectRequest>,
|
||||
@ -253,8 +246,7 @@ where
|
||||
pub fn finish(self) -> Client
|
||||
where
|
||||
M: Transform<DefaultConnector<ConnectorService<S, Io>>, ConnectRequest> + 'static,
|
||||
M::Transform:
|
||||
Service<ConnectRequest, Response = ConnectResponse, Error = SendRequestError>,
|
||||
M::Transform: Service<ConnectRequest, Response = ConnectResponse, Error = SendRequestError>,
|
||||
{
|
||||
let max_redirects = self.max_redirects;
|
||||
|
||||
@ -269,8 +261,7 @@ where
|
||||
fn _finish(self) -> Client
|
||||
where
|
||||
M: Transform<DefaultConnector<ConnectorService<S, Io>>, ConnectRequest> + 'static,
|
||||
M::Transform:
|
||||
Service<ConnectRequest, Response = ConnectResponse, Error = SendRequestError>,
|
||||
M::Transform: Service<ConnectRequest, Response = ConnectResponse, Error = SendRequestError>,
|
||||
{
|
||||
let mut connector = self.connector;
|
||||
|
||||
|
@ -7,19 +7,15 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed, ReadBuf};
|
||||
use actix_http::{body::MessageBody, h1::ClientCodec, Payload, RequestHeadType, ResponseHead};
|
||||
use actix_rt::task::JoinHandle;
|
||||
use bytes::Bytes;
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use h2::client::SendRequest;
|
||||
|
||||
use actix_http::{body::MessageBody, h1::ClientCodec, Payload, RequestHeadType, ResponseHead};
|
||||
|
||||
use super::{error::SendRequestError, h1proto, h2proto, pool::Acquired};
|
||||
use crate::BoxError;
|
||||
|
||||
use super::error::SendRequestError;
|
||||
use super::pool::Acquired;
|
||||
use super::{h1proto, h2proto};
|
||||
|
||||
/// Trait alias for types impl [tokio::io::AsyncRead] and [tokio::io::AsyncWrite].
|
||||
pub trait ConnectionIo: AsyncRead + AsyncWrite + Unpin + 'static {}
|
||||
|
||||
@ -83,10 +79,7 @@ impl<Io: ConnectionIo> AsyncWrite for H1Connection<Io> {
|
||||
self.io_pin_mut().poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<(), io::Error>> {
|
||||
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
|
||||
self.io_pin_mut().poll_shutdown(cx)
|
||||
}
|
||||
|
||||
|
@ -133,11 +133,8 @@ impl<S> Connector<S> {
|
||||
pub fn connector<S1, Io1>(self, connector: S1) -> Connector<S1>
|
||||
where
|
||||
Io1: ActixStream + fmt::Debug + 'static,
|
||||
S1: Service<
|
||||
ConnectInfo<Uri>,
|
||||
Response = TcpConnection<Uri, Io1>,
|
||||
Error = TcpConnectError,
|
||||
> + Clone,
|
||||
S1: Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, Io1>, Error = TcpConnectError>
|
||||
+ Clone,
|
||||
{
|
||||
Connector {
|
||||
connector,
|
||||
@ -189,10 +186,7 @@ where
|
||||
#[doc(hidden)]
|
||||
#[cfg(feature = "openssl")]
|
||||
#[deprecated(since = "3.0.0", note = "Renamed to `Connector::openssl`.")]
|
||||
pub fn ssl(
|
||||
mut self,
|
||||
connector: actix_tls::connect::openssl::reexports::SslConnector,
|
||||
) -> Self {
|
||||
pub fn ssl(mut self, connector: actix_tls::connect::openssl::reexports::SslConnector) -> Self {
|
||||
self.tls = OurTlsConnector::Openssl(connector);
|
||||
self
|
||||
}
|
||||
@ -312,9 +306,7 @@ where
|
||||
|
||||
let tls = match self.tls {
|
||||
#[cfg(feature = "openssl")]
|
||||
OurTlsConnector::OpensslBuilder(builder) => {
|
||||
OurTlsConnector::Openssl(builder.build())
|
||||
}
|
||||
OurTlsConnector::OpensslBuilder(builder) => OurTlsConnector::Openssl(builder.build()),
|
||||
tls => tls,
|
||||
};
|
||||
|
||||
@ -467,9 +459,7 @@ pub struct TcpConnectorService<S: Clone> {
|
||||
|
||||
impl<S, Io> Service<Connect> for TcpConnectorService<S>
|
||||
where
|
||||
S: Service<Connect, Response = TcpConnection<Uri, Io>, Error = ConnectError>
|
||||
+ Clone
|
||||
+ 'static,
|
||||
S: Service<Connect, Response = TcpConnection<Uri, Io>, Error = ConnectError> + Clone + 'static,
|
||||
{
|
||||
type Response = (Io, Protocol);
|
||||
type Error = ConnectError;
|
||||
@ -520,9 +510,8 @@ struct TlsConnectorService<Tcp, Tls> {
|
||||
|
||||
impl<Tcp, Tls, IO> Service<Connect> for TlsConnectorService<Tcp, Tls>
|
||||
where
|
||||
Tcp: Service<Connect, Response = TcpConnection<Uri, IO>, Error = ConnectError>
|
||||
+ Clone
|
||||
+ 'static,
|
||||
Tcp:
|
||||
Service<Connect, Response = TcpConnection<Uri, IO>, Error = ConnectError> + Clone + 'static,
|
||||
Tls: Service<TcpConnection<Uri, IO>, Error = std::io::Error> + Clone + 'static,
|
||||
Tls::Response: IntoConnectionIo,
|
||||
IO: ConnectionIo,
|
||||
|
@ -1,11 +1,9 @@
|
||||
use std::{fmt, io};
|
||||
|
||||
use derive_more::{Display, From};
|
||||
|
||||
use actix_http::error::{HttpError, ParseError};
|
||||
|
||||
#[cfg(feature = "openssl")]
|
||||
use actix_tls::accept::openssl::reexports::Error as OpensslError;
|
||||
use derive_more::{Display, From};
|
||||
|
||||
use crate::BoxError;
|
||||
|
||||
|
@ -18,12 +18,11 @@ use futures_core::{ready, Stream};
|
||||
use futures_util::SinkExt as _;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
use crate::BoxError;
|
||||
|
||||
use super::{
|
||||
connection::{ConnectionIo, H1Connection},
|
||||
error::{ConnectError, SendRequestError},
|
||||
};
|
||||
use crate::BoxError;
|
||||
|
||||
pub(crate) async fn send_request<Io, B>(
|
||||
io: H1Connection<Io>,
|
||||
|
@ -1,28 +1,29 @@
|
||||
use std::future::Future;
|
||||
|
||||
use actix_utils::future::poll_fn;
|
||||
use bytes::Bytes;
|
||||
use h2::{
|
||||
client::{Builder, Connection, SendRequest},
|
||||
SendStream,
|
||||
};
|
||||
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING};
|
||||
use http::{request::Request, Method, Version};
|
||||
use log::trace;
|
||||
|
||||
use actix_http::{
|
||||
body::{BodySize, MessageBody},
|
||||
header::HeaderMap,
|
||||
Payload, RequestHeadType, ResponseHead,
|
||||
};
|
||||
|
||||
use crate::BoxError;
|
||||
use actix_utils::future::poll_fn;
|
||||
use bytes::Bytes;
|
||||
use h2::{
|
||||
client::{Builder, Connection, SendRequest},
|
||||
SendStream,
|
||||
};
|
||||
use http::{
|
||||
header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING},
|
||||
request::Request,
|
||||
Method, Version,
|
||||
};
|
||||
use log::trace;
|
||||
|
||||
use super::{
|
||||
config::ConnectorConfig,
|
||||
connection::{ConnectionIo, H2Connection},
|
||||
error::SendRequestError,
|
||||
};
|
||||
use crate::BoxError;
|
||||
|
||||
pub(crate) async fn send_request<Io, B>(
|
||||
mut io: H2Connection<Io>,
|
||||
|
@ -19,9 +19,11 @@ mod h1proto;
|
||||
mod h2proto;
|
||||
mod pool;
|
||||
|
||||
pub use self::connection::{Connection, ConnectionIo};
|
||||
pub use self::connector::{Connector, ConnectorService};
|
||||
pub use self::error::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
|
||||
pub use self::{
|
||||
connection::{Connection, ConnectionIo},
|
||||
connector::{Connector, ConnectorService},
|
||||
error::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Connect {
|
||||
|
@ -23,11 +23,13 @@ use http::uri::Authority;
|
||||
use pin_project_lite::pin_project;
|
||||
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
|
||||
|
||||
use super::config::ConnectorConfig;
|
||||
use super::connection::{ConnectionInnerType, ConnectionIo, ConnectionType, H2ConnectionInner};
|
||||
use super::error::ConnectError;
|
||||
use super::h2proto::handshake;
|
||||
use super::Connect;
|
||||
use super::{
|
||||
config::ConnectorConfig,
|
||||
connection::{ConnectionInnerType, ConnectionIo, ConnectionType, H2ConnectionInner},
|
||||
error::ConnectError,
|
||||
h2proto::handshake,
|
||||
Connect,
|
||||
};
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Clone, Debug)]
|
||||
pub struct Key {
|
||||
@ -201,7 +203,9 @@ where
|
||||
// check if the connection is still usable
|
||||
if let ConnectionInnerType::H1(ref mut io) = c.conn {
|
||||
let check = ConnectionCheckFuture { io };
|
||||
match check.now_or_never().expect("ConnectionCheckFuture must never yield with Poll::Pending.") {
|
||||
match check.now_or_never().expect(
|
||||
"ConnectionCheckFuture must never yield with Poll::Pending.",
|
||||
) {
|
||||
ConnectionState::Tainted => {
|
||||
inner.close(c.conn);
|
||||
continue;
|
||||
|
@ -13,9 +13,7 @@ use futures_core::{future::LocalBoxFuture, ready};
|
||||
|
||||
use crate::{
|
||||
any_body::AnyBody,
|
||||
client::{
|
||||
Connect as ClientConnect, ConnectError, Connection, ConnectionIo, SendRequestError,
|
||||
},
|
||||
client::{Connect as ClientConnect, ConnectError, Connection, ConnectionIo, SendRequestError},
|
||||
ClientResponse,
|
||||
};
|
||||
|
||||
@ -62,9 +60,9 @@ impl ConnectResponse {
|
||||
pub fn into_client_response(self) -> ClientResponse {
|
||||
match self {
|
||||
ConnectResponse::Client(res) => res,
|
||||
_ => panic!(
|
||||
"ClientResponse only reachable with ConnectResponse::ClientResponse variant"
|
||||
),
|
||||
_ => {
|
||||
panic!("ClientResponse only reachable with ConnectResponse::ClientResponse variant")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,9 +73,9 @@ impl ConnectResponse {
|
||||
pub fn into_tunnel_response(self) -> (ResponseHead, Framed<BoxedSocket, ClientCodec>) {
|
||||
match self {
|
||||
ConnectResponse::Tunnel(head, framed) => (head, framed),
|
||||
_ => panic!(
|
||||
"TunnelResponse only reachable with ConnectResponse::TunnelResponse variant"
|
||||
),
|
||||
_ => {
|
||||
panic!("TunnelResponse only reachable with ConnectResponse::TunnelResponse variant")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ pub use actix_http::{
|
||||
ws::{HandshakeError as WsHandshakeError, ProtocolError as WsProtocolError},
|
||||
StatusCode,
|
||||
};
|
||||
|
||||
use derive_more::{Display, From};
|
||||
use serde_json::error::Error as JsonError;
|
||||
|
||||
|
@ -1,15 +1,14 @@
|
||||
use std::{net, rc::Rc, time::Duration};
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures_core::Stream;
|
||||
use serde::Serialize;
|
||||
|
||||
use actix_http::{
|
||||
body::MessageBody,
|
||||
error::HttpError,
|
||||
header::{HeaderMap, TryIntoHeaderPair},
|
||||
Method, RequestHead, Uri,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use futures_core::Stream;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
client::ClientConfig,
|
||||
|
@ -113,7 +113,6 @@
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
|
||||
pub use actix_http::body;
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
pub use cookie;
|
||||
|
||||
@ -134,18 +133,18 @@ pub mod http {
|
||||
//! Various HTTP related types.
|
||||
|
||||
// TODO: figure out how best to expose http::Error vs actix_http::Error
|
||||
pub use actix_http::{
|
||||
header, uri, ConnectionType, Error, Method, StatusCode, Uri, Version,
|
||||
};
|
||||
pub use actix_http::{header, uri, ConnectionType, Error, Method, StatusCode, Uri, Version};
|
||||
}
|
||||
|
||||
pub use self::builder::ClientBuilder;
|
||||
pub use self::client::{Client, Connect, Connector};
|
||||
pub use self::connect::{BoxConnectorService, BoxedSocket, ConnectRequest, ConnectResponse};
|
||||
pub use self::frozen::{FrozenClientRequest, FrozenSendBuilder};
|
||||
pub use self::request::ClientRequest;
|
||||
#[allow(deprecated)]
|
||||
pub use self::responses::{ClientResponse, JsonBody, MessageBody, ResponseBody};
|
||||
pub use self::sender::SendClientRequest;
|
||||
pub use self::{
|
||||
builder::ClientBuilder,
|
||||
client::{Client, Connect, Connector},
|
||||
connect::{BoxConnectorService, BoxedSocket, ConnectRequest, ConnectResponse},
|
||||
frozen::{FrozenClientRequest, FrozenSendBuilder},
|
||||
request::ClientRequest,
|
||||
sender::SendClientRequest,
|
||||
};
|
||||
|
||||
pub(crate) type BoxError = Box<dyn std::error::Error>;
|
||||
|
@ -1,11 +1,11 @@
|
||||
mod redirect;
|
||||
|
||||
pub use self::redirect::Redirect;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use actix_service::Service;
|
||||
|
||||
pub use self::redirect::Redirect;
|
||||
|
||||
/// Trait for transform a type to another one.
|
||||
/// Both the input and output type should impl [actix_service::Service] trait.
|
||||
pub trait Transform<S, Req> {
|
||||
|
@ -449,8 +449,7 @@ mod tests {
|
||||
}
|
||||
|
||||
async fn test(req: HttpRequest, body: Bytes) -> HttpResponse {
|
||||
if (req.method() == Method::GET || req.method() == Method::HEAD)
|
||||
&& body.is_empty()
|
||||
if (req.method() == Method::GET || req.method() == Method::HEAD) && body.is_empty()
|
||||
{
|
||||
HttpResponse::Ok().finish()
|
||||
} else {
|
||||
@ -550,10 +549,7 @@ mod tests {
|
||||
let port = *req.app_data::<u16>().unwrap();
|
||||
if req.headers().get(header::AUTHORIZATION).is_some() {
|
||||
HttpResponse::Found()
|
||||
.append_header((
|
||||
"location",
|
||||
format!("http://localhost:{}/", port).as_str(),
|
||||
))
|
||||
.append_header(("location", format!("http://localhost:{}/", port).as_str()))
|
||||
.finish()
|
||||
} else {
|
||||
HttpResponse::InternalServerError().finish()
|
||||
|
@ -1,17 +1,18 @@
|
||||
use std::{fmt, net, rc::Rc, time::Duration};
|
||||
|
||||
use base64::prelude::*;
|
||||
use bytes::Bytes;
|
||||
use futures_core::Stream;
|
||||
use serde::Serialize;
|
||||
|
||||
use actix_http::{
|
||||
body::MessageBody,
|
||||
error::HttpError,
|
||||
header::{self, HeaderMap, HeaderValue, TryIntoHeaderPair},
|
||||
ConnectionType, Method, RequestHead, Uri, Version,
|
||||
};
|
||||
use base64::prelude::*;
|
||||
use bytes::Bytes;
|
||||
use futures_core::Stream;
|
||||
use serde::Serialize;
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
use crate::cookie::{Cookie, CookieJar};
|
||||
use crate::{
|
||||
client::ClientConfig,
|
||||
error::{FreezeRequestError, InvalidUrl},
|
||||
@ -20,9 +21,6 @@ use crate::{
|
||||
BoxError,
|
||||
};
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
use crate::cookie::{Cookie, CookieJar};
|
||||
|
||||
/// An HTTP Client request builder
|
||||
///
|
||||
/// This type can be used to construct an instance of `ClientRequest` through a
|
||||
@ -291,10 +289,7 @@ impl ClientRequest {
|
||||
}
|
||||
|
||||
/// Sets the query part of the request
|
||||
pub fn query<T: Serialize>(
|
||||
mut self,
|
||||
query: &T,
|
||||
) -> Result<Self, serde_urlencoded::ser::Error> {
|
||||
pub fn query<T: Serialize>(mut self, query: &T) -> Result<Self, serde_urlencoded::ser::Error> {
|
||||
let mut parts = self.head.uri.clone().into_parts();
|
||||
|
||||
if let Some(path_and_query) = parts.path_and_query {
|
||||
|
@ -8,10 +8,9 @@ mod read_body;
|
||||
mod response;
|
||||
mod response_body;
|
||||
|
||||
pub use self::json_body::JsonBody;
|
||||
pub use self::response::ClientResponse;
|
||||
#[allow(deprecated)]
|
||||
pub use self::response_body::{MessageBody, ResponseBody};
|
||||
pub use self::{json_body::JsonBody, response::ClientResponse};
|
||||
|
||||
/// Default body size limit: 2 MiB
|
||||
const DEFAULT_BODY_LIMIT: usize = 2 * 1024 * 1024;
|
||||
|
@ -7,8 +7,8 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_http::{
|
||||
error::PayloadError, header::HeaderMap, BoxedPayloadStream, Extensions, HttpMessage,
|
||||
Payload, ResponseHead, StatusCode, Version,
|
||||
error::PayloadError, header::HeaderMap, BoxedPayloadStream, Extensions, HttpMessage, Payload,
|
||||
ResponseHead, StatusCode, Version,
|
||||
};
|
||||
use actix_rt::time::{sleep, Sleep};
|
||||
use bytes::Bytes;
|
||||
@ -16,11 +16,10 @@ use futures_core::Stream;
|
||||
use pin_project_lite::pin_project;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use super::{JsonBody, ResponseBody, ResponseTimeout};
|
||||
#[cfg(feature = "cookies")]
|
||||
use crate::cookie::{Cookie, ParseError as CookieParseError};
|
||||
|
||||
use super::{JsonBody, ResponseBody, ResponseTimeout};
|
||||
|
||||
pin_project! {
|
||||
/// Client Response
|
||||
pub struct ClientResponse<S = BoxedPayloadStream> {
|
||||
|
@ -13,15 +13,14 @@ use actix_http::{
|
||||
header::{self, HeaderMap, HeaderName, TryIntoHeaderValue},
|
||||
RequestHead, RequestHeadType,
|
||||
};
|
||||
#[cfg(feature = "__compress")]
|
||||
use actix_http::{encoding::Decoder, header::ContentEncoding, Payload};
|
||||
use actix_rt::time::{sleep, Sleep};
|
||||
use bytes::Bytes;
|
||||
use derive_more::From;
|
||||
use futures_core::Stream;
|
||||
use serde::Serialize;
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
use actix_http::{encoding::Decoder, header::ContentEncoding, Payload};
|
||||
|
||||
use crate::{
|
||||
any_body::AnyBody,
|
||||
client::ClientConfig,
|
||||
@ -106,8 +105,9 @@ impl Future for SendClientRequest {
|
||||
}
|
||||
|
||||
let res = futures_core::ready!(send.as_mut().poll(cx)).map(|res| {
|
||||
res.into_client_response()._timeout(delay.take()).map_body(
|
||||
|head, payload| {
|
||||
res.into_client_response()
|
||||
._timeout(delay.take())
|
||||
.map_body(|head, payload| {
|
||||
if *response_decompress {
|
||||
Payload::Stream {
|
||||
payload: Decoder::from_headers(payload, &head.headers),
|
||||
@ -117,8 +117,7 @@ impl Future for SendClientRequest {
|
||||
payload: Decoder::new(payload, ContentEncoding::Identity),
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
Poll::Ready(res)
|
||||
|
@ -28,15 +28,15 @@
|
||||
|
||||
use std::{fmt, net::SocketAddr, str};
|
||||
|
||||
use base64::prelude::*;
|
||||
|
||||
use actix_codec::Framed;
|
||||
pub use actix_http::ws::{CloseCode, CloseReason, Codec, Frame, Message};
|
||||
use actix_http::{ws, Payload, RequestHead};
|
||||
use actix_rt::time::timeout;
|
||||
use actix_service::Service as _;
|
||||
use base64::prelude::*;
|
||||
|
||||
pub use actix_http::ws::{CloseCode, CloseReason, Codec, Frame, Message};
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
use crate::cookie::{Cookie, CookieJar};
|
||||
use crate::{
|
||||
client::ClientConfig,
|
||||
connect::{BoxedSocket, ConnectRequest},
|
||||
@ -48,9 +48,6 @@ use crate::{
|
||||
ClientResponse,
|
||||
};
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
use crate::cookie::{Cookie, CookieJar};
|
||||
|
||||
/// WebSocket connection.
|
||||
pub struct WebsocketsRequest {
|
||||
pub(crate) head: RequestHead,
|
||||
|
@ -12,19 +12,18 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use actix_http::{HttpService, StatusCode};
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
|
||||
use actix_utils::future::ok;
|
||||
use actix_web::{dev::AppConfig, http::header, web, App, Error, HttpRequest, HttpResponse};
|
||||
use awc::error::{JsonPayloadError, PayloadError, SendRequestError};
|
||||
use base64::prelude::*;
|
||||
use bytes::Bytes;
|
||||
use cookie::Cookie;
|
||||
use futures_util::stream;
|
||||
use rand::Rng;
|
||||
|
||||
use actix_http::{HttpService, StatusCode};
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
|
||||
use actix_web::{dev::AppConfig, http::header, web, App, Error, HttpRequest, HttpResponse};
|
||||
use awc::error::{JsonPayloadError, PayloadError, SendRequestError};
|
||||
|
||||
mod utils;
|
||||
|
||||
const S: &str = "Hello World ";
|
||||
@ -33,9 +32,8 @@ const STR: &str = const_str::repeat!(S, 100);
|
||||
#[actix_rt::test]
|
||||
async fn simple() {
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
)
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })))
|
||||
});
|
||||
|
||||
let request = srv.get("/").insert_header(("x-test", "111")).send();
|
||||
@ -61,9 +59,8 @@ async fn simple() {
|
||||
#[actix_rt::test]
|
||||
async fn json() {
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|_: web::Json<String>| HttpResponse::Ok())),
|
||||
)
|
||||
App::new()
|
||||
.service(web::resource("/").route(web::to(|_: web::Json<String>| HttpResponse::Ok())))
|
||||
});
|
||||
|
||||
let request = srv
|
||||
@ -340,8 +337,7 @@ async fn connection_wait_queue() {
|
||||
.and_then(
|
||||
HttpService::new(map_config(
|
||||
App::new().service(
|
||||
web::resource("/")
|
||||
.route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
@ -449,9 +445,7 @@ async fn no_decompress() {
|
||||
let srv = actix_test::start(|| {
|
||||
App::new()
|
||||
.wrap(actix_web::middleware::Compress::default())
|
||||
.service(
|
||||
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
|
||||
)
|
||||
.service(web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })))
|
||||
});
|
||||
|
||||
let mut res = awc::Client::new()
|
||||
@ -833,12 +827,12 @@ async fn local_address() {
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
|
||||
|
||||
let srv = actix_test::start(move || {
|
||||
App::new().service(web::resource("/").route(web::to(
|
||||
move |req: HttpRequest| async move {
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(move |req: HttpRequest| async move {
|
||||
assert_eq!(req.peer_addr().unwrap().ip(), ip);
|
||||
Ok::<_, Error>(HttpResponse::Ok())
|
||||
},
|
||||
)))
|
||||
})),
|
||||
)
|
||||
});
|
||||
let client = awc::Client::builder().local_address(ip).finish();
|
||||
|
||||
|
@ -5,8 +5,7 @@ extern crate tls_openssl as openssl;
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{map_config, ServiceFactoryExt};
|
||||
use actix_web::http::Version;
|
||||
use actix_web::{dev::AppConfig, web, App, HttpResponse};
|
||||
use actix_web::{dev::AppConfig, http::Version, web, App, HttpResponse};
|
||||
use openssl::{
|
||||
pkey::PKey,
|
||||
ssl::{SslAcceptor, SslConnector, SslMethod, SslVerifyMode},
|
||||
|
@ -2,15 +2,16 @@
|
||||
|
||||
extern crate tls_openssl as openssl;
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
};
|
||||
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, map_config, ServiceFactoryExt};
|
||||
use actix_utils::future::ok;
|
||||
use actix_web::http::Version;
|
||||
use actix_web::{dev::AppConfig, web, App, HttpResponse};
|
||||
use actix_web::{dev::AppConfig, http::Version, web, App, HttpResponse};
|
||||
use openssl::{
|
||||
pkey::PKey,
|
||||
ssl::{SslAcceptor, SslConnector, SslMethod, SslVerifyMode},
|
||||
|
@ -4,9 +4,10 @@
|
||||
use std::io::{Read as _, Write as _};
|
||||
|
||||
pub mod gzip {
|
||||
use super::*;
|
||||
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = GzEncoder::new(Vec::new(), Compression::fast());
|
||||
encoder.write_all(bytes.as_ref()).unwrap();
|
||||
@ -22,9 +23,10 @@ pub mod gzip {
|
||||
}
|
||||
|
||||
pub mod deflate {
|
||||
use super::*;
|
||||
use flate2::{read::ZlibDecoder, write::ZlibEncoder, Compression};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::fast());
|
||||
encoder.write_all(bytes.as_ref()).unwrap();
|
||||
@ -40,9 +42,10 @@ pub mod deflate {
|
||||
}
|
||||
|
||||
pub mod brotli {
|
||||
use super::*;
|
||||
use ::brotli::{reader::Decompressor as BrotliDecoder, CompressorWriter as BrotliEncoder};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = BrotliEncoder::new(
|
||||
Vec::new(),
|
||||
@ -64,9 +67,10 @@ pub mod brotli {
|
||||
}
|
||||
|
||||
pub mod zstd {
|
||||
use super::*;
|
||||
use ::zstd::stream::{read::Decoder, write::Encoder};
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
|
||||
let mut encoder = Encoder::new(Vec::new(), 3).unwrap();
|
||||
encoder.write_all(bytes.as_ref()).unwrap();
|
||||
|
Reference in New Issue
Block a user