Skip to content

Commit b97909f

Browse files
authored
proxy-http: Remove unneeded boilerplate (#651)
There's a lot of needless boilerplate around the HTTP client, mostly due to manual future implementations. These have been converted to boxed futures. Furthermore, the HasSettings trait has been eliminated, in favor of AsRef.
1 parent 6c8d715 commit b97909f

File tree

6 files changed

+171
-327
lines changed

6 files changed

+171
-327
lines changed

linkerd/app/core/src/control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl fmt::Display for ControlAddr {
3434
}
3535

3636
type BalanceBody =
37-
http::balance::PendingUntilFirstDataBody<tower::load::peak_ewma::Handle, http::glue::Body>;
37+
http::balance::PendingUntilFirstDataBody<tower::load::peak_ewma::Handle, hyper::Body>;
3838

3939
type RspBody = linkerd2_http_metrics::requests::ResponseBody<BalanceBody, classify::Eos>;
4040

linkerd/app/inbound/src/endpoint.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ impl Into<SocketAddr> for HttpEndpoint {
5353
}
5454
}
5555

56-
impl http::settings::HasSettings for HttpEndpoint {
57-
fn http_settings(&self) -> http::Settings {
58-
self.settings
56+
impl AsRef<http::Settings> for HttpEndpoint {
57+
fn as_ref(&self) -> &http::Settings {
58+
&self.settings
5959
}
6060
}
6161

@@ -135,9 +135,9 @@ impl http::normalize_uri::ShouldNormalizeUri for Target {
135135
}
136136
}
137137

138-
impl http::settings::HasSettings for Target {
139-
fn http_settings(&self) -> http::Settings {
140-
self.http_settings
138+
impl AsRef<http::Settings> for Target {
139+
fn as_ref(&self) -> &http::Settings {
140+
&self.http_settings
141141
}
142142
}
143143

linkerd/app/outbound/src/endpoint.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,22 @@ impl<'t, T> From<&'t Target<T>> for http::header::HeaderValue {
9898
}
9999
}
100100

101-
impl<T: http::settings::HasSettings> http::normalize_uri::ShouldNormalizeUri for Target<T> {
101+
impl<T: AsRef<http::Settings>> http::normalize_uri::ShouldNormalizeUri for Target<T> {
102102
fn should_normalize_uri(&self) -> Option<http::uri::Authority> {
103103
if let http::Settings::Http1 {
104104
was_absolute_form: false,
105105
..
106-
} = self.inner.http_settings()
106+
} = *self.inner.as_ref()
107107
{
108108
return Some(self.addr.to_http_authority());
109109
}
110110
None
111111
}
112112
}
113113

114-
impl<T: http::settings::HasSettings> http::settings::HasSettings for Target<T> {
115-
fn http_settings(&self) -> http::Settings {
116-
self.inner.http_settings()
114+
impl<T: AsRef<http::Settings>> AsRef<http::Settings> for Target<T> {
115+
fn as_ref(&self) -> &http::Settings {
116+
self.inner.as_ref()
117117
}
118118
}
119119

@@ -199,7 +199,7 @@ impl std::hash::Hash for HttpEndpoint {
199199
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
200200
self.addr.hash(state);
201201
self.identity.hash(state);
202-
http::settings::HasSettings::http_settings(self).hash(state);
202+
self.settings.hash(state);
203203
// Ignore metadata.
204204
}
205205
}
@@ -216,22 +216,9 @@ impl Into<SocketAddr> for HttpEndpoint {
216216
}
217217
}
218218

219-
impl http::settings::HasSettings for HttpEndpoint {
220-
fn http_settings(&self) -> http::Settings {
221-
match self.settings {
222-
Settings::Http1 {
223-
keep_alive,
224-
wants_h1_upgrade,
225-
was_absolute_form,
226-
} => Settings::Http1 {
227-
keep_alive,
228-
wants_h1_upgrade,
229-
// Always use absolute form when an onverride is present.
230-
was_absolute_form: self.metadata.authority_override().is_some()
231-
|| was_absolute_form,
232-
},
233-
settings => settings,
234-
}
219+
impl AsRef<http::Settings> for HttpEndpoint {
220+
fn as_ref(&self) -> &http::Settings {
221+
&self.settings
235222
}
236223
}
237224

@@ -291,14 +278,28 @@ impl MapEndpoint<Concrete<http::Settings>, Metadata> for FromMetadata {
291278
Conditional::None(tls::ReasonForNoPeerName::NotProvidedByServiceDiscovery.into())
292279
});
293280

281+
let settings = match concrete.inner.inner {
282+
Settings::Http1 {
283+
keep_alive,
284+
wants_h1_upgrade,
285+
was_absolute_form,
286+
} => Settings::Http1 {
287+
keep_alive,
288+
wants_h1_upgrade,
289+
// Always use absolute form when an onverride is present.
290+
was_absolute_form: metadata.authority_override().is_some() || was_absolute_form,
291+
},
292+
settings => settings,
293+
};
294+
294295
Target {
295296
// Use the logical addr for the target.
296297
addr: concrete.inner.addr.clone(),
297298
inner: HttpEndpoint {
298299
addr,
299300
identity,
300301
metadata,
301-
settings: concrete.inner.inner,
302+
settings,
302303
},
303304
}
304305
}

linkerd/app/outbound/src/orig_proto_upgrade.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::proxy::http::{
2-
orig_proto,
3-
settings::{HasSettings, Settings},
4-
};
1+
use crate::proxy::http::{orig_proto, settings::Settings};
52
use crate::svc::stack;
63
use crate::{HttpEndpoint, Target};
74
use futures::{ready, TryFuture};
@@ -56,7 +53,7 @@ where
5653
return Either::B(self.inner.new_service(endpoint));
5754
}
5855

59-
let was_absolute = endpoint.http_settings().was_absolute_form();
56+
let was_absolute = endpoint.inner.settings.was_absolute_form();
6057
trace!(
6158
header = %orig_proto::L5D_ORIG_PROTO,
6259
was_absolute,
@@ -84,7 +81,7 @@ where
8481
fn call(&mut self, mut endpoint: Target<HttpEndpoint>) -> Self::Future {
8582
let can_upgrade = endpoint.inner.can_use_orig_proto();
8683

87-
let was_absolute = endpoint.http_settings().was_absolute_form();
84+
let was_absolute = endpoint.inner.settings.was_absolute_form();
8885

8986
if can_upgrade {
9087
trace!(

0 commit comments

Comments
 (0)