Skip to content

Commit aa1dbd7

Browse files
authored
refactor(proxy/http): extricate Body middleware types (#3382)
* refactor(proxy/http): move types to `linkerd-http-classify` (#3382) in this case we already had a crate defining the classify traits, but the http body and other assorted middleware were defined in `linkerd-proxy-http`. this commit moves those types to the `linkerd-http-classify` crate, which astute readers may notice, is a concrete step towards simplifying the `linkerd-proxy-http` crate's upgrade process. one small detail worth calling out: we implement `http_body::Body` directly, to avoid taking on a `hyper` dependency. otherwise, nothing has changed in the `channel`, `gate`, and `insert` middleware. Signed-off-by: katelyn martin <[email protected]> * refactor(proxy/http): create `linkerd-http-retain` crate (#3382) this moves the `Retain` middleware from `linkerd-proxy-http` into a new `linkerd-http-retain` crate. as previously, reëxports are added to make this a backwards compatible change. this moves another http body middleware out of the proxy's core http crate. great news. Signed-off-by: katelyn martin <[email protected]> * refactor(proxy/http): create `linkerd-http-stream-timeouts` crate (#3382) this commit outlines the stream timeout middleware, pulling it out of `linkerd-proxy-http` and into a standalone crate. again, reëxports are added to make this a backwards compatible change. Signed-off-by: katelyn martin <[email protected]> * refactor(proxy/http): create `linkerd-http-override-authority` crate (#3382) NB: based on #3379 and #3380. this pull the `override_authority` submodule out of `linkerd-http-proxy` and into a standalone crate. Signed-off-by: katelyn martin <[email protected]> * refactor(proxy/http): move `is_bad_request()` into `upgrade` (#3382) this is only used in once place, so as a brief chore before we move the upgrade submodule out into its own crate, we pull `is_bad_request()` next to its call site. Signed-off-by: katelyn martin <[email protected]> * refactor(proxy/http): create `linkerd-http-upgrade` crate (#3382) this moves the inter-related `upgrade` and `glue` submodules out of the `linkerd-proxy-http` library and into a new standalone crate. Signed-off-by: katelyn martin <[email protected]> --------- Signed-off-by: katelyn martin <[email protected]>
1 parent 0ff6f48 commit aa1dbd7

File tree

24 files changed

+327
-124
lines changed

24 files changed

+327
-124
lines changed

Cargo.lock

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,8 +1705,18 @@ dependencies = [
17051705
name = "linkerd-http-classify"
17061706
version = "0.1.0"
17071707
dependencies = [
1708+
"futures",
17081709
"http",
1710+
"http-body",
17091711
"linkerd-error",
1712+
"linkerd-http-box",
1713+
"linkerd-stack",
1714+
"linkerd-tracing",
1715+
"pin-project",
1716+
"tokio",
1717+
"tokio-test",
1718+
"tower-test",
1719+
"tracing",
17101720
]
17111721

17121722
[[package]]
@@ -1753,6 +1763,16 @@ dependencies = [
17531763
"tracing",
17541764
]
17551765

1766+
[[package]]
1767+
name = "linkerd-http-override-authority"
1768+
version = "0.1.0"
1769+
dependencies = [
1770+
"http",
1771+
"linkerd-stack",
1772+
"tower",
1773+
"tracing",
1774+
]
1775+
17561776
[[package]]
17571777
name = "linkerd-http-prom"
17581778
version = "0.1.0"
@@ -1772,6 +1792,17 @@ dependencies = [
17721792
"tokio",
17731793
]
17741794

1795+
[[package]]
1796+
name = "linkerd-http-retain"
1797+
version = "0.1.0"
1798+
dependencies = [
1799+
"http",
1800+
"http-body",
1801+
"linkerd-stack",
1802+
"pin-project",
1803+
"tower",
1804+
]
1805+
17751806
[[package]]
17761807
name = "linkerd-http-retry"
17771808
version = "0.1.0"
@@ -1808,6 +1839,44 @@ dependencies = [
18081839
"url",
18091840
]
18101841

1842+
[[package]]
1843+
name = "linkerd-http-stream-timeouts"
1844+
version = "0.1.0"
1845+
dependencies = [
1846+
"futures",
1847+
"http",
1848+
"http-body",
1849+
"linkerd-error",
1850+
"linkerd-stack",
1851+
"parking_lot",
1852+
"pin-project",
1853+
"thiserror",
1854+
"tokio",
1855+
"tracing",
1856+
]
1857+
1858+
[[package]]
1859+
name = "linkerd-http-upgrade"
1860+
version = "0.1.0"
1861+
dependencies = [
1862+
"bytes",
1863+
"drain",
1864+
"futures",
1865+
"http",
1866+
"http-body",
1867+
"hyper",
1868+
"linkerd-duplex",
1869+
"linkerd-error",
1870+
"linkerd-http-version",
1871+
"linkerd-io",
1872+
"linkerd-stack",
1873+
"pin-project",
1874+
"tokio",
1875+
"tower",
1876+
"tracing",
1877+
"try-lock",
1878+
]
1879+
18111880
[[package]]
18121881
name = "linkerd-http-version"
18131882
version = "0.1.0"
@@ -2178,6 +2247,10 @@ dependencies = [
21782247
"linkerd-http-executor",
21792248
"linkerd-http-h2",
21802249
"linkerd-http-insert",
2250+
"linkerd-http-override-authority",
2251+
"linkerd-http-retain",
2252+
"linkerd-http-stream-timeouts",
2253+
"linkerd-http-upgrade",
21812254
"linkerd-http-version",
21822255
"linkerd-io",
21832256
"linkerd-proxy-balance",

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ members = [
3131
"linkerd/http/h2",
3232
"linkerd/http/insert",
3333
"linkerd/http/metrics",
34+
"linkerd/http/override-authority",
3435
"linkerd/http/prom",
36+
"linkerd/http/retain",
3537
"linkerd/http/retry",
3638
"linkerd/http/route",
39+
"linkerd/http/stream-timeouts",
40+
"linkerd/http/upgrade",
3741
"linkerd/http/version",
3842
"linkerd/identity",
3943
"linkerd/idle-cache",

linkerd/http/classify/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ edition = "2021"
77
publish = false
88

99
[dependencies]
10+
futures = { version = "0.3", default-features = false }
1011
http = "0.2"
12+
http-body = "0.4"
13+
pin-project = "1"
14+
tokio = { version = "1", default-features = false }
15+
tracing = "0.1"
1116

1217
linkerd-error = { path = "../../error" }
18+
linkerd-http-box = { path = "../../http/box" }
19+
linkerd-stack = { path = "../../stack" }
20+
21+
[dev-dependencies]
22+
tokio-test = "0.4"
23+
tower-test = "0.4"
24+
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }

linkerd/proxy/http/src/classify/channel.rs renamed to linkerd/http/classify/src/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ where
207207

208208
// === impl ResponseBody ===
209209

210-
impl<C, B> hyper::body::HttpBody for ResponseBody<C, B>
210+
impl<C, B> http_body::Body for ResponseBody<C, B>
211211
where
212212
C: ClassifyEos + Unpin,
213-
B: hyper::body::HttpBody<Error = Error>,
213+
B: http_body::Body<Error = Error>,
214214
{
215215
type Data = B::Data;
216216
type Error = B::Error;

linkerd/proxy/http/src/classify/gate.rs renamed to linkerd/http/classify/src/gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::classify::{BroadcastClassification, ClassifyResponse};
1+
use crate::{channel::BroadcastClassification, ClassifyResponse};
22
use linkerd_stack::{gate, layer, ExtractParam, Gate, NewService};
33
use std::marker::PhantomData;
44
use tokio::sync::mpsc;
File renamed without changes.

linkerd/http/classify/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
use linkerd_error::Error;
55

6+
pub use self::{
7+
channel::{BroadcastClassification, NewBroadcastClassification, Tx},
8+
gate::{NewClassifyGate, NewClassifyGateSet},
9+
insert::{InsertClassifyResponse, NewInsertClassifyResponse},
10+
};
11+
12+
pub mod channel;
13+
pub mod gate;
14+
mod insert;
15+
616
/// Determines how a request's response should be classified.
717
pub trait Classify {
818
type Class: Clone + Send + Sync + 'static;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "linkerd-http-override-authority"
3+
version = "0.1.0"
4+
authors = ["Linkerd Developers <[email protected]>"]
5+
license = "Apache-2.0"
6+
edition = "2021"
7+
publish = false
8+
description = """
9+
Tower middleware to override request authorities.
10+
"""
11+
12+
[dependencies]
13+
http = "0.2"
14+
tower = { version = "0.4", default-features = false }
15+
tracing = "0.1"
16+
17+
linkerd-stack = { path = "../../stack" }

linkerd/proxy/http/src/override_authority.rs renamed to linkerd/http/override-authority/src/lib.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use http::{header::AsHeaderName, uri::Authority};
1+
use http::{
2+
header::AsHeaderName,
3+
uri::{self, Authority},
4+
};
25
use linkerd_stack::{layer, NewService, Param};
36
use std::{
47
fmt,
@@ -23,6 +26,27 @@ pub struct OverrideAuthority<S, H> {
2326
inner: S,
2427
}
2528

29+
/// Sets the [`Authority`] of the given URI.
30+
pub fn set_authority(uri: &mut uri::Uri, auth: Authority) {
31+
let mut parts = uri::Parts::from(std::mem::take(uri));
32+
33+
parts.authority = Some(auth);
34+
35+
// If this was an origin-form target (path only),
36+
// then we can't *only* set the authority, as that's
37+
// an illegal target (such as `example.com/docs`).
38+
//
39+
// But don't set a scheme if this was authority-form (CONNECT),
40+
// since that would change its meaning (like `https://example.com`).
41+
if parts.path_and_query.is_some() {
42+
parts.scheme = Some(http::uri::Scheme::HTTP);
43+
}
44+
45+
let new = http::uri::Uri::from_parts(parts).expect("absolute uri");
46+
47+
*uri = new;
48+
}
49+
2650
// === impl NewOverrideAuthority ===
2751

2852
impl<H: Clone, N> NewOverrideAuthority<H, N> {

linkerd/http/retain/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "linkerd-http-retain"
3+
version = "0.1.0"
4+
authors = ["Linkerd Developers <[email protected]>"]
5+
license = "Apache-2.0"
6+
edition = "2021"
7+
publish = false
8+
description = """
9+
Tower middleware to manage service lifecycles.
10+
11+
This is mostly intended to support cache eviction.
12+
"""
13+
14+
[dependencies]
15+
http = "0.2"
16+
http-body = "0.4"
17+
pin-project = "1"
18+
tower = { version = "0.4", default-features = false }
19+
20+
linkerd-stack = { path = "../../stack" }

0 commit comments

Comments
 (0)