mirror of https://github.com/fafhrd91/actix-web
Removed *_extra methods from Connection trait
This commit is contained in:
parent
e4dfd6a1e7
commit
c36dfe14db
|
@ -1,5 +1,4 @@
|
||||||
use std::{fmt, io, time};
|
use std::{fmt, io, time};
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||||
use bytes::{Buf, Bytes};
|
use bytes::{Buf, Bytes};
|
||||||
|
@ -9,9 +8,8 @@ use h2::client::SendRequest;
|
||||||
|
|
||||||
use crate::body::MessageBody;
|
use crate::body::MessageBody;
|
||||||
use crate::h1::ClientCodec;
|
use crate::h1::ClientCodec;
|
||||||
use crate::message::{RequestHead, RequestHeadType, ResponseHead};
|
use crate::message::{RequestHeadType, ResponseHead};
|
||||||
use crate::payload::Payload;
|
use crate::payload::Payload;
|
||||||
use crate::header::HeaderMap;
|
|
||||||
|
|
||||||
use super::error::SendRequestError;
|
use super::error::SendRequestError;
|
||||||
use super::pool::{Acquired, Protocol};
|
use super::pool::{Acquired, Protocol};
|
||||||
|
@ -29,17 +27,9 @@ pub trait Connection {
|
||||||
fn protocol(&self) -> Protocol;
|
fn protocol(&self) -> Protocol;
|
||||||
|
|
||||||
/// Send request and body
|
/// Send request and body
|
||||||
fn send_request<B: MessageBody + 'static>(
|
fn send_request<B: MessageBody + 'static, H: Into<RequestHeadType>>(
|
||||||
self,
|
self,
|
||||||
head: RequestHead,
|
head: H,
|
||||||
body: B,
|
|
||||||
) -> Self::Future;
|
|
||||||
|
|
||||||
/// Send request, extra headers and body
|
|
||||||
fn send_request_extra<B: MessageBody + 'static>(
|
|
||||||
self,
|
|
||||||
head: Rc<RequestHead>,
|
|
||||||
extra_headers: Option<HeaderMap>,
|
|
||||||
body: B,
|
body: B,
|
||||||
) -> Self::Future;
|
) -> Self::Future;
|
||||||
|
|
||||||
|
@ -49,14 +39,7 @@ pub trait Connection {
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Send request, returns Response and Framed
|
/// Send request, returns Response and Framed
|
||||||
fn open_tunnel(self, head: RequestHead) -> Self::TunnelFuture;
|
fn open_tunnel<H: Into<RequestHeadType>>(self, head: H) -> Self::TunnelFuture;
|
||||||
|
|
||||||
/// Send request and extra headers, returns Response and Framed
|
|
||||||
fn open_tunnel_extra(
|
|
||||||
self,
|
|
||||||
head: Rc<RequestHead>,
|
|
||||||
extra_headers: Option<HeaderMap>,
|
|
||||||
) -> Self::TunnelFuture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait ConnectionLifetime: AsyncRead + AsyncWrite + 'static {
|
pub(crate) trait ConnectionLifetime: AsyncRead + AsyncWrite + 'static {
|
||||||
|
@ -122,46 +105,22 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_request<B: MessageBody + 'static>(
|
fn send_request<B: MessageBody + 'static, H: Into<RequestHeadType>>(
|
||||||
mut self,
|
mut self,
|
||||||
head: RequestHead,
|
head: H,
|
||||||
body: B,
|
body: B,
|
||||||
) -> Self::Future {
|
) -> Self::Future {
|
||||||
match self.io.take().unwrap() {
|
match self.io.take().unwrap() {
|
||||||
ConnectionType::H1(io) => Box::new(h1proto::send_request(
|
ConnectionType::H1(io) => Box::new(h1proto::send_request(
|
||||||
io,
|
io,
|
||||||
RequestHeadType::Owned(head),
|
head.into(),
|
||||||
body,
|
body,
|
||||||
self.created,
|
self.created,
|
||||||
self.pool,
|
self.pool,
|
||||||
)),
|
)),
|
||||||
ConnectionType::H2(io) => Box::new(h2proto::send_request(
|
ConnectionType::H2(io) => Box::new(h2proto::send_request(
|
||||||
io,
|
io,
|
||||||
RequestHeadType::Owned(head),
|
head.into(),
|
||||||
body,
|
|
||||||
self.created,
|
|
||||||
self.pool,
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_request_extra<B: MessageBody + 'static>(
|
|
||||||
mut self,
|
|
||||||
head: Rc<RequestHead>,
|
|
||||||
extra_headers: Option<HeaderMap>,
|
|
||||||
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),
|
|
||||||
body,
|
body,
|
||||||
self.created,
|
self.created,
|
||||||
self.pool,
|
self.pool,
|
||||||
|
@ -180,28 +139,10 @@ where
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Send request, returns Response and Framed
|
/// Send request, returns Response and Framed
|
||||||
fn open_tunnel(mut self, head: RequestHead) -> Self::TunnelFuture {
|
fn open_tunnel<H: Into<RequestHeadType>>(mut self, head: H) -> Self::TunnelFuture {
|
||||||
match self.io.take().unwrap() {
|
match self.io.take().unwrap() {
|
||||||
ConnectionType::H1(io) => {
|
ConnectionType::H1(io) => {
|
||||||
Either::A(Box::new(h1proto::open_tunnel(io, RequestHeadType::Owned(head))))
|
Either::A(Box::new(h1proto::open_tunnel(io, head.into())))
|
||||||
}
|
|
||||||
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<RequestHead>, extra_headers: Option<HeaderMap>) -> Self::TunnelFuture {
|
|
||||||
match self.io.take().unwrap() {
|
|
||||||
ConnectionType::H1(io) => {
|
|
||||||
Either::A(Box::new(h1proto::open_tunnel(io, RequestHeadType::Rc(head, extra_headers))))
|
|
||||||
}
|
}
|
||||||
ConnectionType::H2(io) => {
|
ConnectionType::H2(io) => {
|
||||||
if let Some(mut pool) = self.pool.take() {
|
if let Some(mut pool) = self.pool.take() {
|
||||||
|
@ -239,9 +180,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_request<RB: MessageBody + 'static>(
|
fn send_request<RB: MessageBody + 'static, H: Into<RequestHeadType>>(
|
||||||
self,
|
self,
|
||||||
head: RequestHead,
|
head: H,
|
||||||
body: RB,
|
body: RB,
|
||||||
) -> Self::Future {
|
) -> Self::Future {
|
||||||
match self {
|
match self {
|
||||||
|
@ -250,18 +191,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_request_extra<RB: MessageBody + 'static>(
|
|
||||||
self,
|
|
||||||
head: Rc<RequestHead>,
|
|
||||||
extra_headers: Option<HeaderMap>,
|
|
||||||
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<
|
type TunnelFuture = Box<
|
||||||
dyn Future<
|
dyn Future<
|
||||||
Item = (ResponseHead, Framed<Self::Io, ClientCodec>),
|
Item = (ResponseHead, Framed<Self::Io, ClientCodec>),
|
||||||
|
@ -270,7 +199,7 @@ where
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Send request, returns Response and Framed
|
/// Send request, returns Response and Framed
|
||||||
fn open_tunnel(self, head: RequestHead) -> Self::TunnelFuture {
|
fn open_tunnel<H: Into<RequestHeadType>>(self, head: H) -> Self::TunnelFuture {
|
||||||
match self {
|
match self {
|
||||||
EitherConnection::A(con) => Box::new(
|
EitherConnection::A(con) => Box::new(
|
||||||
con.open_tunnel(head)
|
con.open_tunnel(head)
|
||||||
|
@ -282,19 +211,6 @@ where
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_tunnel_extra(self, head: Rc<RequestHead>, extra_headers: Option<HeaderMap>) -> 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<A, B> {
|
pub enum EitherIo<A, B> {
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub use self::config::{KeepAlive, ServiceConfig};
|
||||||
pub use self::error::{Error, ResponseError, Result};
|
pub use self::error::{Error, ResponseError, Result};
|
||||||
pub use self::extensions::Extensions;
|
pub use self::extensions::Extensions;
|
||||||
pub use self::httpmessage::HttpMessage;
|
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::payload::{Payload, PayloadStream};
|
||||||
pub use self::request::Request;
|
pub use self::request::Request;
|
||||||
pub use self::response::{Response, ResponseBuilder};
|
pub use self::response::{Response, ResponseBuilder};
|
||||||
|
|
|
@ -205,6 +205,12 @@ impl AsRef<RequestHead> for RequestHeadType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<RequestHead> for RequestHeadType {
|
||||||
|
fn from(head: RequestHead) -> Self {
|
||||||
|
RequestHeadType::Owned(head)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ResponseHead {
|
pub struct ResponseHead {
|
||||||
pub version: Version,
|
pub version: Version,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use actix_http::client::{
|
||||||
Connect as ClientConnect, ConnectError, Connection, SendRequestError,
|
Connect as ClientConnect, ConnectError, Connection, SendRequestError,
|
||||||
};
|
};
|
||||||
use actix_http::h1::ClientCodec;
|
use actix_http::h1::ClientCodec;
|
||||||
use actix_http::{RequestHead, ResponseHead};
|
use actix_http::{RequestHead, RequestHeadType, ResponseHead};
|
||||||
use actix_http::http::HeaderMap;
|
use actix_http::http::HeaderMap;
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use futures::{Future, Poll};
|
use futures::{Future, Poll};
|
||||||
|
@ -82,7 +82,7 @@ where
|
||||||
})
|
})
|
||||||
.from_err()
|
.from_err()
|
||||||
// send request
|
// 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)),
|
.map(|(head, payload)| ClientResponse::new(head, payload)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ where
|
||||||
})
|
})
|
||||||
.from_err()
|
.from_err()
|
||||||
// send request
|
// 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)),
|
.map(|(head, payload)| ClientResponse::new(head, payload)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ where
|
||||||
})
|
})
|
||||||
.from_err()
|
.from_err()
|
||||||
// send request
|
// send request
|
||||||
.and_then(move |connection| connection.open_tunnel(head))
|
.and_then(move |connection| connection.open_tunnel(RequestHeadType::from(head)))
|
||||||
.map(|(head, framed)| {
|
.map(|(head, framed)| {
|
||||||
let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io))));
|
let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io))));
|
||||||
(head, framed)
|
(head, framed)
|
||||||
|
@ -155,7 +155,7 @@ where
|
||||||
})
|
})
|
||||||
.from_err()
|
.from_err()
|
||||||
// send request
|
// 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)| {
|
.map(|(head, framed)| {
|
||||||
let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io))));
|
let framed = framed.map_io(|io| BoxedSocket(Box::new(Socket(io))));
|
||||||
(head, framed)
|
(head, framed)
|
||||||
|
|
Loading…
Reference in New Issue