Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy: enable HTTP CONNECT request support #1200

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ dependencies = [
"futures-mpsc-lossy 0.3.0",
"futures-watch 0.1.0 (git+https://github.com/carllerche/better-future)",
"h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"inotify 0.5.2-dev (git+https://github.com/inotify-rs/inotify)",
"ipnet 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -167,7 +167,7 @@ dependencies = [
"tower-util 0.1.0 (git+https://github.com/tower-rs/tower)",
"trust-dns-resolver 0.9.0 (git+https://github.com/bluejekyll/trust-dns)",
"try-lock 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"webpki 0.18.0-alpha4 (registry+https://github.com/rust-lang/crates.io-index)",
]

Expand All @@ -178,7 +178,7 @@ dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"prost 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prost-derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prost-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -377,7 +377,7 @@ dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand All @@ -404,11 +404,12 @@ dependencies = [

[[package]]
name = "http"
version = "0.1.5"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
Expand All @@ -418,16 +419,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "hyper"
version = "0.12.2"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"net2 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -508,6 +510,11 @@ dependencies = [
"either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "itoa"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "kernel32-sys"
version = "0.2.2"
Expand Down Expand Up @@ -894,7 +901,7 @@ dependencies = [
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
Expand All @@ -919,7 +926,7 @@ dependencies = [
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)",
"sct 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"webpki 0.18.0-alpha4 (registry+https://github.com/rust-lang/crates.io-index)",
]

Expand All @@ -939,7 +946,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ring 0.13.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
Expand Down Expand Up @@ -1243,7 +1250,7 @@ dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"prost 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tower-h2 0.1.0 (git+https://github.com/tower-rs/tower-h2)",
Expand All @@ -1268,7 +1275,7 @@ dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-connect 0.1.0 (git+https://github.com/carllerche/tokio-connect)",
"tokio-io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
Expand All @@ -1282,7 +1289,7 @@ source = "git+https://github.com/tower-rs/tower-h2#760f9fc1c83c3a96edb6fbddb6b0c
dependencies = [
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tower-balance 0.1.0 (git+https://github.com/tower-rs/tower)",
"tower-h2 0.1.0 (git+https://github.com/tower-rs/tower-h2)",
"tower-service 0.1.0 (git+https://github.com/tower-rs/tower)",
Expand Down Expand Up @@ -1413,7 +1420,7 @@ dependencies = [

[[package]]
name = "untrusted"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
Expand Down Expand Up @@ -1452,7 +1459,7 @@ version = "0.18.0-alpha4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ring 0.13.0-alpha5 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
Expand Down Expand Up @@ -1571,9 +1578,9 @@ dependencies = [
"checksum h2 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6229ac66d3392dd83288fe04defd4b353354b15bbe07820d53dda063a736afcc"
"checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82"
"checksum hostname 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "58fab6e177434b0bb4cd344a4dabaa5bd6d7a8d792b1885aebcae7af1091d1cb"
"checksum http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "75df369fd52c60635208a4d3e694777c099569b3dcf4844df8f652dc004644ab"
"checksum http 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4fbced8864b04c030eebcb7d0dc3a81ba5231ac559f5116a29a8ba83ecee22cd"
"checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37"
"checksum hyper 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ad39a4f15051ccd4ea6adf44df851e00fd9062c71734391d806246b94e69dc1f"
"checksum hyper 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f31c3ce511142fac936539abd3315bdc303a6e501fac5b77e0824310d542d081"
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
"checksum indexmap 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9378f1f3923647a9aea6af4c6b5de68cc8a71415459ad25ef191191c48f5b7"
"checksum inotify 0.5.2-dev (git+https://github.com/inotify-rs/inotify)" = "<none>"
Expand All @@ -1582,6 +1589,7 @@ dependencies = [
"checksum ipconfig 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec4e18c0a0d4340870c14284293632d8421f419008371422dd327892b88877c"
"checksum ipnet 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51268c3a27ad46afd1cca0bbf423a5be2e9fd3e6a7534736c195f0f834b763ef"
"checksum itertools 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b07332223953b5051bceb67e8c4700aa65291535568e1f12408c43c4a42c0394"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef"
Expand Down Expand Up @@ -1683,7 +1691,7 @@ dependencies = [
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum untrusted 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70afa43c8c5d23a53a3c39ec9b56232c5badc19f6bb5ad529c1d6448a7241365"
"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f"
"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
Expand Down
2 changes: 1 addition & 1 deletion proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ futures-watch = { git = "https://github.com/carllerche/better-future" }
h2 = "0.1.10"
http = "0.1"
httparse = "1.2"
hyper = "0.12.2"
hyper = "0.12.3"
ipnet = "1.0"
log = "0.4.1"
indexmap = "1.0.0"
Expand Down
7 changes: 4 additions & 3 deletions proxy/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,16 @@ impl Protocol {
return Protocol::Http2
}

let authority_part = req.uri().authority_part();
let was_absolute_form = authority_part.is_some();
let was_absolute_form = h1::is_absolute_form(req.uri());
trace!(
"Protocol::detect(); req.uri='{:?}'; was_absolute_form={:?};",
req.uri(), was_absolute_form
);
// If the request has an authority part, use that as the host part of
// the key for an HTTP/1.x request.
let host = authority_part
let host = req
.uri()
.authority_part()
.cloned()
.or_else(|| h1::authority_from_host(req))
.map(Host::Authority)
Expand Down
16 changes: 13 additions & 3 deletions proxy/src/transparency/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use bind;
use task::BoxExecutor;
use telemetry::sensor::http::RequestBody;
use super::glue::{BodyPayload, HttpBody, HyperConnect};
use super::upgrade::Http11Upgrade;
use super::upgrade::{HttpConnect, Http11Upgrade};

type HyperClient<C, B> =
hyper::Client<HyperConnect<C>, BodyPayload<RequestBody<B>>>;
Expand Down Expand Up @@ -216,9 +216,15 @@ where
ClientServiceInner::Http1(ref h1) => {
let mut req = req.map(BodyPayload::new);
let upgrade = req.extensions_mut().remove::<Http11Upgrade>();
let is_http_connect = if upgrade.is_some() {
req.method() == &http::Method::CONNECT
} else {
false
};
ClientServiceFuture::Http1 {
future: h1.request(req),
upgrade,
is_http_connect,
}
},
ClientServiceInner::Http2(ref mut h2) => {
Expand All @@ -232,6 +238,7 @@ pub enum ClientServiceFuture {
Http1 {
future: hyper::client::ResponseFuture,
upgrade: Option<Http11Upgrade>,
is_http_connect: bool,
},
Http2(tower_h2::client::ResponseFuture),
}
Expand All @@ -242,13 +249,16 @@ impl Future for ClientServiceFuture {

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
match self {
ClientServiceFuture::Http1 { future, upgrade } => {
ClientServiceFuture::Http1 { future, upgrade, is_http_connect } => {
match future.poll() {
Ok(Async::Ready(res)) => {
let res = res.map(move |b| HttpBody::Http1 {
let mut res = res.map(move |b| HttpBody::Http1 {
body: Some(b),
upgrade: upgrade.take(),
});
if *is_http_connect {
res.extensions_mut().insert(HttpConnect);
}
Ok(Async::Ready(res))
},
Ok(Async::NotReady) => Ok(Async::NotReady),
Expand Down
19 changes: 12 additions & 7 deletions proxy/src/transparency/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum HttpBody {
}

/// Glue for `tower_h2::Body`s to be used in hyper.
#[derive(Debug)]
#[derive(Debug, Default)]
pub(super) struct BodyPayload<B> {
body: B,
}
Expand Down Expand Up @@ -255,14 +255,19 @@ where
>;

fn call(&mut self, mut req: http::Request<Self::ReqBody>) -> Self::Future {
if let &http::Method::CONNECT = req.method() {
debug!("HTTP/1.1 CONNECT not supported");
let res = http::Response::builder()
.status(http::StatusCode::BAD_GATEWAY)
.body(BodyPayload::new(Default::default()))
.expect("building response with empty body should not error!");
// Should this rejection happen later in the Service stack?
//
// Rejecting here means telemetry doesn't record anything about it...
//
// At the same time, this stuff is specifically HTTP1, so it feels
// proper to not have the HTTP2 requests going through it...
if h1::is_bad_request(&req) {
let mut res = http::Response::default();
*res.status_mut() = http::StatusCode::BAD_REQUEST;
return Either::B(future::ok(res));
}


req.extensions_mut().insert(self.srv_ctx.clone());

let upgrade = if h1::wants_upgrade(&req) {
Expand Down
Loading