diff --git a/actix-http/src/client/connection.rs b/actix-http/src/client/connection.rs index e511b04ff..d2b94b3e5 100644 --- a/actix-http/src/client/connection.rs +++ b/actix-http/src/client/connection.rs @@ -1,5 +1,4 @@ use std::{fmt, io, time}; -use std::rc::Rc; use actix_codec::{AsyncRead, AsyncWrite, Framed}; use bytes::{Buf, Bytes}; @@ -9,9 +8,8 @@ use h2::client::SendRequest; use crate::body::MessageBody; use crate::h1::ClientCodec; -use crate::message::{RequestHead, RequestHeadType, ResponseHead}; +use crate::message::{RequestHeadType, ResponseHead}; use crate::payload::Payload; -use crate::header::HeaderMap; use super::error::SendRequestError; use super::pool::{Acquired, Protocol}; @@ -29,17 +27,9 @@ pub trait Connection { fn protocol(&self) -> Protocol; /// Send request and body - fn send_request( + fn send_request>( self, - head: RequestHead, - body: B, - ) -> Self::Future; - - /// Send request, extra headers and body - fn send_request_extra( - self, - head: Rc, - extra_headers: Option, + head: H, body: B, ) -> Self::Future; @@ -49,14 +39,7 @@ pub trait Connection { >; /// Send request, returns Response and Framed - fn open_tunnel(self, head: RequestHead) -> Self::TunnelFuture; - - /// Send request and extra headers, returns Response and Framed - fn open_tunnel_extra( - self, - head: Rc, - extra_headers: Option, - ) -> Self::TunnelFuture; + fn open_tunnel>(self, head: H) -> Self::TunnelFuture; } pub(crate) trait ConnectionLifetime: AsyncRead + AsyncWrite + 'static { @@ -122,46 +105,22 @@ where } } - fn send_request( + fn send_request>( mut self, - head: RequestHead, + head: H, body: B, ) -> Self::Future { match self.io.take().unwrap() { ConnectionType::H1(io) => Box::new(h1proto::send_request( io, - RequestHeadType::Owned(head), + head.into(), body, self.created, self.pool, )), ConnectionType::H2(io) => Box::new(h2proto::send_request( io, - RequestHeadType::Owned(head), - body, - self.created, - self.pool, - )), - } - } - - fn send_request_extra( - mut self, - head: Rc, - extra_headers: Option, - body: B, - ) -> Self::Future { - match self.io.take().unwrap() { - ConnectionType::H1(io) => Box::new(h1proto::send_request( - io, - RequestHeadType::Rc(head, extra_headers), - body, - self.created, - self.pool, - )), - ConnectionType::H2(io) => Box::new(h2proto::send_request( - io, - RequestHeadType::Rc(head, extra_headers), + head.into(), body, self.created, self.pool, @@ -180,28 +139,10 @@ where >; /// Send request, returns Response and Framed - fn open_tunnel(mut self, head: RequestHead) -> Self::TunnelFuture { + fn open_tunnel>(mut self, head: H) -> Self::TunnelFuture { match self.io.take().unwrap() { ConnectionType::H1(io) => { - Either::A(Box::new(h1proto::open_tunnel(io, RequestHeadType::Owned(head)))) - } - ConnectionType::H2(io) => { - if let Some(mut pool) = self.pool.take() { - pool.release(IoConnection::new( - ConnectionType::H2(io), - self.created, - None, - )); - } - Either::B(err(SendRequestError::TunnelNotSupported)) - } - } - } - - fn open_tunnel_extra(mut self, head: Rc, extra_headers: Option) -> Self::TunnelFuture { - match self.io.take().unwrap() { - ConnectionType::H1(io) => { - Either::A(Box::new(h1proto::open_tunnel(io, RequestHeadType::Rc(head, extra_headers)))) + Either::A(Box::new(h1proto::open_tunnel(io, head.into()))) } ConnectionType::H2(io) => { if let Some(mut pool) = self.pool.take() { @@ -239,9 +180,9 @@ where } } - fn send_request( + fn send_request>( self, - head: RequestHead, + head: H, body: RB, ) -> Self::Future { match self { @@ -250,18 +191,6 @@ where } } - fn send_request_extra( - self, - head: Rc, - extra_headers: Option, - body: RB, - ) -> Self::Future { - match self { - EitherConnection::A(con) => con.send_request_extra(head, extra_headers, body), - EitherConnection::B(con) => con.send_request_extra(head, extra_headers, body), - } - } - type TunnelFuture = Box< dyn Future< Item = (ResponseHead, Framed), @@ -270,7 +199,7 @@ where >; /// Send request, returns Response and Framed - fn open_tunnel(self, head: RequestHead) -> Self::TunnelFuture { + fn open_tunnel>(self, head: H) -> Self::TunnelFuture { match self { EitherConnection::A(con) => Box::new( con.open_tunnel(head) @@ -282,19 +211,6 @@ where ), } } - - fn open_tunnel_extra(self, head: Rc, extra_headers: Option) -> Self::TunnelFuture { - match self { - EitherConnection::A(con) => Box::new( - con.open_tunnel_extra(head, extra_headers) - .map(|(head, framed)| (head, framed.map_io(EitherIo::A))), - ), - EitherConnection::B(con) => Box::new( - con.open_tunnel_extra(head, extra_headers) - .map(|(head, framed)| (head, framed.map_io(EitherIo::B))), - ), - } - } } pub enum EitherIo { diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs index 6b8874b23..b57fdddce 100644 --- a/actix-http/src/lib.rs +++ b/actix-http/src/lib.rs @@ -39,7 +39,7 @@ pub use self::config::{KeepAlive, ServiceConfig}; pub use self::error::{Error, ResponseError, Result}; pub use self::extensions::Extensions; pub use self::httpmessage::HttpMessage; -pub use self::message::{Message, RequestHead, ResponseHead}; +pub use self::message::{Message, RequestHead, RequestHeadType, ResponseHead}; pub use self::payload::{Payload, PayloadStream}; pub use self::request::Request; pub use self::response::{Response, ResponseBuilder}; diff --git a/actix-http/src/message.rs b/actix-http/src/message.rs index cda700f7d..316df2611 100644 --- a/actix-http/src/message.rs +++ b/actix-http/src/message.rs @@ -205,6 +205,12 @@ impl AsRef for RequestHeadType { } } +impl From for RequestHeadType { + fn from(head: RequestHead) -> Self { + RequestHeadType::Owned(head) + } +} + #[derive(Debug)] pub struct ResponseHead { pub version: Version, diff --git a/awc/src/connect.rs b/awc/src/connect.rs index 63b8a895a..82fd6a759 100644 --- a/awc/src/connect.rs +++ b/awc/src/connect.rs @@ -7,7 +7,7 @@ use actix_http::client::{ Connect as ClientConnect, ConnectError, Connection, SendRequestError, }; use actix_http::h1::ClientCodec; -use actix_http::{RequestHead, ResponseHead}; +use actix_http::{RequestHead, RequestHeadType, ResponseHead}; use actix_http::http::HeaderMap; use actix_service::Service; use futures::{Future, Poll}; @@ -82,7 +82,7 @@ where }) .from_err() // send request - .and_then(move |connection| connection.send_request(head, body)) + .and_then(move |connection| connection.send_request(RequestHeadType::from(head), body)) .map(|(head, payload)| ClientResponse::new(head, payload)), ) } @@ -103,7 +103,7 @@ where }) .from_err() // send request - .and_then(move |connection| connection.send_request_extra(head, extra_headers, body)) + .and_then(move |connection| connection.send_request(RequestHeadType::Rc(head, extra_headers), body)) .map(|(head, payload)| ClientResponse::new(head, payload)), ) } @@ -127,7 +127,7 @@ where }) .from_err() // send request - .and_then(move |connection| connection.open_tunnel(head)) + .and_then(move |connection| connection.open_tunnel(RequestHeadType::from(head))) .map(|(head, framed)| { let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io)))); (head, framed) @@ -155,7 +155,7 @@ where }) .from_err() // send request - .and_then(move |connection| connection.open_tunnel_extra(head, extra_headers)) + .and_then(move |connection| connection.open_tunnel(RequestHeadType::Rc(head, extra_headers))) .map(|(head, framed)| { let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io)))); (head, framed)