Move HTTP-specific `proxy` modules into proxy::http (#93)
To prepare to move http-specific proxying logic from bind.rs into proxy, let's carve out a proxy::http module for HTTP-specific behavior.
This commit is contained in:
parent
ccd5d21978
commit
bbf296668b
20
src/bind.rs
20
src/bind.rs
|
@ -13,24 +13,24 @@ use control::destination::Endpoint;
|
|||
use ctx;
|
||||
use svc::{MakeClient, Reconnect};
|
||||
use telemetry;
|
||||
use proxy::{self, HttpBody, h1, orig_proto};
|
||||
use proxy;
|
||||
use transport;
|
||||
use tls;
|
||||
use ctx::transport::TlsStatus;
|
||||
use watch_service::{WatchService, Rebind};
|
||||
|
||||
/// An HTTP `Service` that is created for each `Endpoint` and `Protocol`.
|
||||
pub type Stack<B> = orig_proto::Upgrade<NormalizeUri<WatchTls<B>>>;
|
||||
pub type Stack<B> = proxy::http::orig_proto::Upgrade<NormalizeUri<WatchTls<B>>>;
|
||||
|
||||
type WatchTls<B> = WatchService<tls::ConditionalClientConfig, RebindTls<B>>;
|
||||
|
||||
/// An HTTP `Service` that is created for each `Endpoint`, `Protocol`, and client
|
||||
/// TLS configuration.
|
||||
pub type TlsStack<B> = telemetry::http::service::Http<HttpService<B>, B, HttpBody>;
|
||||
pub type TlsStack<B> = telemetry::http::service::Http<HttpService<B>, B, proxy::http::Body>;
|
||||
|
||||
type HttpService<B> = Reconnect<
|
||||
Arc<ctx::transport::Client>,
|
||||
proxy::Client<
|
||||
proxy::http::Client<
|
||||
transport::metrics::Connect<transport::Connect>,
|
||||
::logging::ClientExecutor<&'static str, SocketAddr>,
|
||||
telemetry::http::service::RequestBody<B>,
|
||||
|
@ -263,7 +263,7 @@ where
|
|||
client_ctx.clone(),
|
||||
Reconnect::new(
|
||||
client_ctx.clone(),
|
||||
proxy::Client::new(protocol, connect, log.executor())
|
||||
proxy::http::Client::new(protocol, connect, log.executor())
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ where
|
|||
let normalize_uri = NormalizeUri::new(watch_tls, protocol.was_absolute_form());
|
||||
|
||||
// Upgrade HTTP/1.1 requests to be HTTP/2 if the endpoint supports HTTP/2.
|
||||
orig_proto::Upgrade::new(normalize_uri, protocol.is_http2())
|
||||
proxy::http::orig_proto::Upgrade::new(normalize_uri, protocol.is_http2())
|
||||
}
|
||||
|
||||
pub fn bind_service(&self, ep: &Endpoint, protocol: &Protocol) -> BoundService<B> {
|
||||
|
@ -384,7 +384,7 @@ where
|
|||
// absolute form.
|
||||
!self.was_absolute_form
|
||||
{
|
||||
h1::normalize_our_view_of_uri(&mut request);
|
||||
proxy::http::h1::normalize_our_view_of_uri(&mut request);
|
||||
}
|
||||
self.inner.call(request)
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ impl Protocol {
|
|||
return Protocol::Http2;
|
||||
}
|
||||
|
||||
let was_absolute_form = h1::is_absolute_form(req.uri());
|
||||
let was_absolute_form = proxy::http::h1::is_absolute_form(req.uri());
|
||||
trace!(
|
||||
"Protocol::detect(); req.uri='{:?}'; was_absolute_form={:?};",
|
||||
req.uri(), was_absolute_form
|
||||
|
@ -451,7 +451,7 @@ impl Protocol {
|
|||
// the key for an HTTP/1.x request.
|
||||
let host = Host::detect(req);
|
||||
|
||||
let is_h1_upgrade = h1::wants_upgrade(req);
|
||||
let is_h1_upgrade = proxy::http::h1::wants_upgrade(req);
|
||||
|
||||
Protocol::Http1 {
|
||||
host,
|
||||
|
@ -496,7 +496,7 @@ impl Host {
|
|||
.uri()
|
||||
.authority_part()
|
||||
.cloned()
|
||||
.or_else(|| h1::authority_from_host(req))
|
||||
.or_else(|| proxy::http::h1::authority_from_host(req))
|
||||
.map(Host::Authority)
|
||||
.unwrap_or_else(|| Host::NoAuthority)
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ use tower_h2;
|
|||
|
||||
use bind;
|
||||
use ctx;
|
||||
use proxy::h2_router::Recognize;
|
||||
use proxy::orig_proto;
|
||||
use proxy::http::router::Recognize;
|
||||
use proxy::http::orig_proto;
|
||||
|
||||
type Bind<B> = bind::Bind<ctx::Proxy, B>;
|
||||
|
||||
|
@ -100,7 +100,7 @@ mod tests {
|
|||
use std::net;
|
||||
|
||||
use http;
|
||||
use proxy::h2_router::Recognize;
|
||||
use proxy::http::router::Recognize;
|
||||
|
||||
use super::Inbound;
|
||||
use bind::{self, Bind, Host};
|
||||
|
|
|
@ -95,8 +95,7 @@ use bind::Bind;
|
|||
use conditional::Conditional;
|
||||
use inbound::Inbound;
|
||||
use task::MainRuntime;
|
||||
use proxy::{HttpBody, Server};
|
||||
use proxy::h2_router::{self, Router, Recognize};
|
||||
use proxy::http::router::{Router, Recognize};
|
||||
use svc::Layer;
|
||||
use telemetry::http::timestamp_request_open;
|
||||
use transport::{BoundPort, Connection};
|
||||
|
@ -417,7 +416,7 @@ where
|
|||
E: Error + Send + 'static,
|
||||
F: Error + Send + 'static,
|
||||
R: Recognize<
|
||||
Request = http::Request<HttpBody>,
|
||||
Request = http::Request<proxy::http::Body>,
|
||||
Response = http::Response<B>,
|
||||
Error = E,
|
||||
RouteError = F,
|
||||
|
@ -438,10 +437,10 @@ where
|
|||
// TODO replace with a metrics module that is registered to the server
|
||||
// transport.
|
||||
let stack = timestamp_request_open::Layer::new()
|
||||
.bind(h2_router::Make::new(router));
|
||||
.bind(proxy::http::router::Make::new(router));
|
||||
|
||||
let listen_addr = bound_port.local_addr();
|
||||
let server = Server::new(
|
||||
let server = proxy::Server::new(
|
||||
listen_addr,
|
||||
proxy_ctx,
|
||||
transport_registry,
|
||||
|
|
|
@ -16,11 +16,11 @@ use tower_h2_balance::{PendingUntilFirstData, PendingUntilFirstDataBody};
|
|||
use bind::{self, Bind, Protocol};
|
||||
use control::destination::{self, Resolution};
|
||||
use ctx;
|
||||
use proxy::h2_router::Recognize;
|
||||
use proxy::{self, http::h1};
|
||||
use proxy::http::router::Recognize;
|
||||
use svc::MakeClient;
|
||||
use telemetry::http::service::{ResponseBody as SensorBody};
|
||||
use timeout::Timeout;
|
||||
use proxy::{h1, HttpBody};
|
||||
use transport::{DnsNameAndPort, Host, HostAndPort};
|
||||
|
||||
type BindProtocol<B> = bind::BindProtocol<ctx::Proxy, B>;
|
||||
|
@ -142,7 +142,7 @@ where
|
|||
type Request = http::Request<B>;
|
||||
type Response = http::Response<PendingUntilFirstDataBody<
|
||||
load::peak_ewma::Handle,
|
||||
SensorBody<HttpBody>,
|
||||
SensorBody<proxy::http::Body>,
|
||||
>>;
|
||||
type Error = <Self::Service as tower::Service>::Error;
|
||||
type Key = (Destination, Protocol);
|
||||
|
|
|
@ -9,10 +9,10 @@ use tower_service::{Service, NewService};
|
|||
use tower_h2;
|
||||
|
||||
use bind;
|
||||
use proxy::http::glue::{BodyPayload, HttpBody, HyperConnect};
|
||||
use proxy::http::h1;
|
||||
use proxy::http::upgrade::{HttpConnect, Http11Upgrade};
|
||||
use task::BoxExecutor;
|
||||
use super::glue::{BodyPayload, HttpBody, HyperConnect};
|
||||
use super::h1;
|
||||
use super::upgrade::{HttpConnect, Http11Upgrade};
|
||||
|
||||
use std::{self, fmt};
|
||||
|
|
@ -17,8 +17,8 @@ use tower_h2;
|
|||
|
||||
use ctx::transport::{Server as ServerCtx};
|
||||
use drain;
|
||||
use super::h1;
|
||||
use super::upgrade::Http11Upgrade;
|
||||
use proxy::http::h1;
|
||||
use proxy::http::upgrade::Http11Upgrade;
|
||||
use task::{BoxSendFuture, ErasedExecutor, Executor};
|
||||
|
||||
/// Glue between `hyper::Body` and `tower_h2::RecvBody`.
|
||||
|
@ -35,13 +35,13 @@ pub enum HttpBody {
|
|||
|
||||
/// Glue for `tower_h2::Body`s to be used in hyper.
|
||||
#[derive(Debug, Default)]
|
||||
pub(super) struct BodyPayload<B> {
|
||||
pub(in proxy) struct BodyPayload<B> {
|
||||
body: B,
|
||||
}
|
||||
|
||||
/// Glue for a `tower::Service` to used as a `hyper::server::Service`.
|
||||
#[derive(Debug)]
|
||||
pub(super) struct HyperServerSvc<S, E> {
|
||||
pub(in proxy) struct HyperServerSvc<S, E> {
|
||||
service: S,
|
||||
srv_ctx: Arc<ServerCtx>,
|
||||
/// Watch any spawned HTTP/1.1 upgrade tasks.
|
||||
|
@ -52,36 +52,36 @@ pub(super) struct HyperServerSvc<S, E> {
|
|||
}
|
||||
|
||||
/// Future returned by `HyperServerSvc`.
|
||||
pub(super) struct HyperServerSvcFuture<F> {
|
||||
pub(in proxy) struct HyperServerSvcFuture<F> {
|
||||
inner: F,
|
||||
}
|
||||
|
||||
/// Glue for any `Service` taking an h2 body to receive an `HttpBody`.
|
||||
#[derive(Debug)]
|
||||
pub(super) struct HttpBodySvc<S> {
|
||||
pub(in proxy) struct HttpBodySvc<S> {
|
||||
service: S,
|
||||
}
|
||||
|
||||
/// Glue for any `NewService` taking an h2 body to receive an `HttpBody`.
|
||||
#[derive(Clone)]
|
||||
pub(super) struct HttpBodyNewSvc<N> {
|
||||
pub(in proxy) struct HttpBodyNewSvc<N> {
|
||||
new_service: N,
|
||||
}
|
||||
|
||||
/// Future returned by `HttpBodyNewSvc`.
|
||||
pub(super) struct HttpBodyNewSvcFuture<F> {
|
||||
pub(in proxy) struct HttpBodyNewSvcFuture<F> {
|
||||
inner: F,
|
||||
}
|
||||
|
||||
/// Glue for any `tokio_connect::Connect` to implement `hyper::client::Connect`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(super) struct HyperConnect<C> {
|
||||
pub(in proxy) struct HyperConnect<C> {
|
||||
connect: C,
|
||||
absolute_form: bool,
|
||||
}
|
||||
|
||||
/// Future returned by `HyperConnect`.
|
||||
pub(super) struct HyperConnectFuture<F> {
|
||||
pub(in proxy) struct HyperConnectFuture<F> {
|
||||
inner: F,
|
||||
absolute_form: bool,
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ impl Drop for HttpBody {
|
|||
|
||||
impl<B> BodyPayload<B> {
|
||||
/// Wrap a `tower_h2::Body` into a `Stream` hyper can understand.
|
||||
pub fn new(body: B) -> Self {
|
||||
pub(in proxy) fn new(body: B) -> Self {
|
||||
BodyPayload {
|
||||
body,
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ where
|
|||
// ===== impl HyperServerSvc =====
|
||||
|
||||
impl<S, E> HyperServerSvc<S, E> {
|
||||
pub fn new(
|
||||
pub(in proxy) fn new(
|
||||
service: S,
|
||||
srv_ctx: Arc<ServerCtx>,
|
||||
upgrade_drain_signal: drain::Watch,
|
||||
|
@ -347,7 +347,7 @@ impl<N> HttpBodyNewSvc<N>
|
|||
where
|
||||
N: NewService<Request=http::Request<HttpBody>>,
|
||||
{
|
||||
pub fn new(new_service: N) -> Self {
|
||||
pub(in proxy) fn new(new_service: N) -> Self {
|
||||
HttpBodyNewSvc {
|
||||
new_service,
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ where
|
|||
C: Connect,
|
||||
C::Future: 'static,
|
||||
{
|
||||
pub fn new(connect: C, absolute_form: bool) -> Self {
|
||||
pub(in proxy) fn new(connect: C, absolute_form: bool) -> Self {
|
||||
HyperConnect {
|
||||
connect,
|
||||
absolute_form,
|
|
@ -0,0 +1,9 @@
|
|||
pub mod client;
|
||||
pub(super) mod glue;
|
||||
pub mod h1;
|
||||
pub mod router;
|
||||
pub mod upgrade;
|
||||
pub mod orig_proto;
|
||||
|
||||
pub use self::client::{Client, Error as ClientError};
|
||||
pub use self::glue::HttpBody as Body;
|
|
@ -6,7 +6,7 @@ use std::{fmt, error};
|
|||
use std::sync::Arc;
|
||||
|
||||
use ctx;
|
||||
use svc::{MakeClient, Service};
|
||||
use svc;
|
||||
|
||||
extern crate linkerd2_proxy_router;
|
||||
|
||||
|
@ -22,7 +22,7 @@ where
|
|||
router: Router<R>,
|
||||
}
|
||||
|
||||
pub struct H2Router<R>
|
||||
pub struct Service<R>
|
||||
where
|
||||
R: Recognize,
|
||||
R::Error: error::Error,
|
||||
|
@ -38,7 +38,7 @@ where
|
|||
R::Error: error::Error,
|
||||
R::RouteError: fmt::Display,
|
||||
{
|
||||
inner: <Router<R> as Service>::Future,
|
||||
inner: <Router<R> as svc::Service>::Future,
|
||||
}
|
||||
|
||||
// ===== impl Make =====
|
||||
|
@ -70,7 +70,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<R, A, B> MakeClient<Arc<ctx::transport::Server>> for Make<R>
|
||||
impl<R, A, B> svc::MakeClient<Arc<ctx::transport::Server>> for Make<R>
|
||||
where
|
||||
R: Recognize<Request = http::Request<A>, Response = http::Response<B>>,
|
||||
R: Send + Sync + 'static,
|
||||
|
@ -80,11 +80,11 @@ where
|
|||
B: Default + Send + 'static,
|
||||
{
|
||||
type Error = ();
|
||||
type Client = H2Router<R>;
|
||||
type Client = Service<R>;
|
||||
|
||||
fn make_client(&self, _: &Arc<ctx::transport::Server>) -> Result<Self::Client, Self::Error> {
|
||||
let inner = self.router.clone();
|
||||
Ok(H2Router { inner })
|
||||
Ok(Service { inner })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,17 +115,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
// ===== impl Router =====
|
||||
// ===== impl Service =====
|
||||
|
||||
impl<R, B> Service for H2Router<R>
|
||||
impl<R, B> svc::Service for Service<R>
|
||||
where
|
||||
R: Recognize<Response = http::Response<B>>,
|
||||
R::Error: error::Error,
|
||||
R::RouteError: fmt::Display,
|
||||
B: Default,
|
||||
{
|
||||
type Request = <Router<R> as Service>::Request;
|
||||
type Response = <Router<R> as Service>::Response;
|
||||
type Request = <Router<R> as svc::Service>::Request;
|
||||
type Response = <Router<R> as svc::Service>::Response;
|
||||
type Error = h2::Error;
|
||||
type Future = ResponseFuture<R>;
|
||||
|
|
@ -8,7 +8,7 @@ use hyper::upgrade::OnUpgrade;
|
|||
use try_lock::TryLock;
|
||||
|
||||
use drain;
|
||||
use super::tcp;
|
||||
use proxy::tcp;
|
||||
use task::{ErasedExecutor, Executor};
|
||||
|
||||
/// A type inserted into `http::Extensions` to bridge together HTTP Upgrades.
|
|
@ -13,16 +13,9 @@
|
|||
//! This module is intended only to store the infrastructure for building a
|
||||
//! proxy. The specific logic implemented by a proxy should live elsewhere.
|
||||
|
||||
mod client;
|
||||
mod glue;
|
||||
pub mod h1;
|
||||
pub mod h2_router;
|
||||
mod upgrade;
|
||||
pub mod orig_proto;
|
||||
pub mod http;
|
||||
mod protocol;
|
||||
mod server;
|
||||
mod tcp;
|
||||
|
||||
pub use self::client::{Client, Error as ClientError};
|
||||
pub use self::glue::HttpBody;
|
||||
pub use self::server::Server;
|
||||
|
|
|
@ -18,9 +18,9 @@ use ctx::transport::{Server as ServerCtx};
|
|||
use drain;
|
||||
use svc::{MakeClient, Service};
|
||||
use transport::{self, Connection, GetOriginalDst, Peek};
|
||||
use super::glue::{HttpBody, HttpBodyNewSvc, HyperServerSvc};
|
||||
use super::protocol::Protocol;
|
||||
use super::tcp;
|
||||
use proxy::http::glue::{HttpBody, HttpBodyNewSvc, HyperServerSvc};
|
||||
use proxy::protocol::Protocol;
|
||||
use proxy::tcp;
|
||||
|
||||
/// A protocol-transparent Server!
|
||||
///
|
||||
|
|
|
@ -6,7 +6,7 @@ use tower_h2::Body;
|
|||
|
||||
use ctx;
|
||||
use telemetry::{http::event, tap};
|
||||
use proxy::ClientError;
|
||||
use proxy::http::ClientError;
|
||||
|
||||
use super::record::Record;
|
||||
use super::service::{Http, RequestBody};
|
||||
|
|
|
@ -10,7 +10,7 @@ use tower_service::Service;
|
|||
use tower_h2::Body;
|
||||
|
||||
use ctx;
|
||||
use proxy::ClientError;
|
||||
use proxy::http::ClientError;
|
||||
|
||||
use super::event::{self, Event};
|
||||
use super::sensors::Handle;
|
||||
|
|
Loading…
Reference in New Issue