diff --git a/src/bind.rs b/src/bind.rs index 042263285..7789a9dda 100644 --- a/src/bind.rs +++ b/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 = orig_proto::Upgrade>>; +pub type Stack = proxy::http::orig_proto::Upgrade>>; type WatchTls = WatchService>; /// An HTTP `Service` that is created for each `Endpoint`, `Protocol`, and client /// TLS configuration. -pub type TlsStack = telemetry::http::service::Http, B, HttpBody>; +pub type TlsStack = telemetry::http::service::Http, B, proxy::http::Body>; type HttpService = Reconnect< Arc, - proxy::Client< + proxy::http::Client< transport::metrics::Connect, ::logging::ClientExecutor<&'static str, SocketAddr>, telemetry::http::service::RequestBody, @@ -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 { @@ -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) } diff --git a/src/inbound.rs b/src/inbound.rs index f23383e7a..8260ffafe 100644 --- a/src/inbound.rs +++ b/src/inbound.rs @@ -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 = bind::Bind; @@ -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}; diff --git a/src/lib.rs b/src/lib.rs index 68d07580e..78d58f290 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, + Request = http::Request, Response = http::Response, 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, diff --git a/src/outbound.rs b/src/outbound.rs index 88f0964f6..4ec0d3877 100644 --- a/src/outbound.rs +++ b/src/outbound.rs @@ -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 = bind::BindProtocol; @@ -142,7 +142,7 @@ where type Request = http::Request; type Response = http::Response, + SensorBody, >>; type Error = ::Error; type Key = (Destination, Protocol); diff --git a/src/proxy/client.rs b/src/proxy/http/client.rs similarity index 98% rename from src/proxy/client.rs rename to src/proxy/http/client.rs index 57374e578..8a9cda472 100644 --- a/src/proxy/client.rs +++ b/src/proxy/http/client.rs @@ -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}; diff --git a/src/proxy/glue.rs b/src/proxy/http/glue.rs similarity index 94% rename from src/proxy/glue.rs rename to src/proxy/http/glue.rs index 3056f643c..302605993 100644 --- a/src/proxy/glue.rs +++ b/src/proxy/http/glue.rs @@ -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 { +pub(in proxy) struct BodyPayload { body: B, } /// Glue for a `tower::Service` to used as a `hyper::server::Service`. #[derive(Debug)] -pub(super) struct HyperServerSvc { +pub(in proxy) struct HyperServerSvc { service: S, srv_ctx: Arc, /// Watch any spawned HTTP/1.1 upgrade tasks. @@ -52,36 +52,36 @@ pub(super) struct HyperServerSvc { } /// Future returned by `HyperServerSvc`. -pub(super) struct HyperServerSvcFuture { +pub(in proxy) struct HyperServerSvcFuture { inner: F, } /// Glue for any `Service` taking an h2 body to receive an `HttpBody`. #[derive(Debug)] -pub(super) struct HttpBodySvc { +pub(in proxy) struct HttpBodySvc { service: S, } /// Glue for any `NewService` taking an h2 body to receive an `HttpBody`. #[derive(Clone)] -pub(super) struct HttpBodyNewSvc { +pub(in proxy) struct HttpBodyNewSvc { new_service: N, } /// Future returned by `HttpBodyNewSvc`. -pub(super) struct HttpBodyNewSvcFuture { +pub(in proxy) struct HttpBodyNewSvcFuture { inner: F, } /// Glue for any `tokio_connect::Connect` to implement `hyper::client::Connect`. #[derive(Debug, Clone)] -pub(super) struct HyperConnect { +pub(in proxy) struct HyperConnect { connect: C, absolute_form: bool, } /// Future returned by `HyperConnect`. -pub(super) struct HyperConnectFuture { +pub(in proxy) struct HyperConnectFuture { inner: F, absolute_form: bool, } @@ -183,7 +183,7 @@ impl Drop for HttpBody { impl BodyPayload { /// 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 HyperServerSvc { - pub fn new( + pub(in proxy) fn new( service: S, srv_ctx: Arc, upgrade_drain_signal: drain::Watch, @@ -347,7 +347,7 @@ impl HttpBodyNewSvc where N: NewService>, { - 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, diff --git a/src/proxy/h1.rs b/src/proxy/http/h1.rs similarity index 100% rename from src/proxy/h1.rs rename to src/proxy/http/h1.rs diff --git a/src/proxy/http/mod.rs b/src/proxy/http/mod.rs new file mode 100644 index 000000000..5289aa6b0 --- /dev/null +++ b/src/proxy/http/mod.rs @@ -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; diff --git a/src/proxy/orig_proto.rs b/src/proxy/http/orig_proto.rs similarity index 100% rename from src/proxy/orig_proto.rs rename to src/proxy/http/orig_proto.rs diff --git a/src/proxy/h2_router.rs b/src/proxy/http/router.rs similarity index 90% rename from src/proxy/h2_router.rs rename to src/proxy/http/router.rs index 4de8c70f9..ed8a2bfe2 100644 --- a/src/proxy/h2_router.rs +++ b/src/proxy/http/router.rs @@ -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, } -pub struct H2Router +pub struct Service where R: Recognize, R::Error: error::Error, @@ -38,7 +38,7 @@ where R::Error: error::Error, R::RouteError: fmt::Display, { - inner: as Service>::Future, + inner: as svc::Service>::Future, } // ===== impl Make ===== @@ -70,7 +70,7 @@ where } } -impl MakeClient> for Make +impl svc::MakeClient> for Make where R: Recognize, Response = http::Response>, R: Send + Sync + 'static, @@ -80,11 +80,11 @@ where B: Default + Send + 'static, { type Error = (); - type Client = H2Router; + type Client = Service; fn make_client(&self, _: &Arc) -> Result { let inner = self.router.clone(); - Ok(H2Router { inner }) + Ok(Service { inner }) } } @@ -115,17 +115,17 @@ where } } -// ===== impl Router ===== +// ===== impl Service ===== -impl Service for H2Router +impl svc::Service for Service where R: Recognize>, R::Error: error::Error, R::RouteError: fmt::Display, B: Default, { - type Request = as Service>::Request; - type Response = as Service>::Response; + type Request = as svc::Service>::Request; + type Response = as svc::Service>::Response; type Error = h2::Error; type Future = ResponseFuture; diff --git a/src/proxy/upgrade.rs b/src/proxy/http/upgrade.rs similarity index 99% rename from src/proxy/upgrade.rs rename to src/proxy/http/upgrade.rs index c71612c90..ddf79ebd8 100644 --- a/src/proxy/upgrade.rs +++ b/src/proxy/http/upgrade.rs @@ -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. diff --git a/src/proxy/mod.rs b/src/proxy/mod.rs index 36969edac..6828030d6 100644 --- a/src/proxy/mod.rs +++ b/src/proxy/mod.rs @@ -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; diff --git a/src/proxy/server.rs b/src/proxy/server.rs index 53eed22f8..ad8ee209d 100644 --- a/src/proxy/server.rs +++ b/src/proxy/server.rs @@ -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! /// diff --git a/src/telemetry/http/sensors.rs b/src/telemetry/http/sensors.rs index 3ce8af5e4..c54305f5c 100644 --- a/src/telemetry/http/sensors.rs +++ b/src/telemetry/http/sensors.rs @@ -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}; diff --git a/src/telemetry/http/service.rs b/src/telemetry/http/service.rs index 1a9920003..e9acd996e 100644 --- a/src/telemetry/http/service.rs +++ b/src/telemetry/http/service.rs @@ -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;