Skip to content

Commit ea51362

Browse files
authored
chore(proxy/http): address hyper deprecations in ServeHttp<N> (#3459)
see linkerd/linkerd2#8733 for more information on upgrading to hyper 1.0. this commit is based upon #3456, and #3457. this commit is also contingent upon hyperium/hyper#3796, which backports the server connection builder's `max_pending_accept_reset_streams()` method. this commit addresses hyper deprecations in `ServeHttp<N>`, which defines a reusable HTTP/1 and HTTP/2 server for the linkerd proxy. essentially, this commit replaces the singular `Http<E>` with a pair of http/1 and http/2 specific connection `Builder`s. method names no longer have `http2_*` prefixes, otherwise nothing about the connection setup has been changed. in the `Service` implementation, we delegate to the appropriate builder based upon the protocol version. Signed-off-by: katelyn martin <[email protected]>
1 parent f2ad745 commit ea51362

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

linkerd/proxy/http/src/server.rs

+23-24
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ pub struct NewServeHttp<X, N> {
3030
params: X,
3131
}
3232

33-
/// Serves HTTP connectionswith an inner service.
33+
/// Serves HTTP connections with an inner service.
3434
#[derive(Clone, Debug)]
3535
pub struct ServeHttp<N> {
3636
version: Version,
37-
#[allow(deprecated)] // linkerd/linkerd2#8733
38-
server: hyper::server::conn::Http<TracingExecutor>,
37+
http1: hyper::server::conn::http1::Builder,
38+
http2: hyper::server::conn::http2::Builder<TracingExecutor>,
3939
inner: N,
4040
drain: drain::Watch,
4141
}
@@ -76,36 +76,38 @@ where
7676
max_pending_accept_reset_streams,
7777
} = h2;
7878

79-
#[allow(deprecated)] // linkerd/linkerd2#8733
80-
let mut srv = hyper::server::conn::Http::new().with_executor(TracingExecutor);
79+
let mut http2 = hyper::server::conn::http2::Builder::new(TracingExecutor);
8180
match flow_control {
8281
None => {}
8382
Some(h2::FlowControl::Adaptive) => {
84-
srv.http2_adaptive_window(true);
83+
http2.adaptive_window(true);
8584
}
8685
Some(h2::FlowControl::Fixed {
8786
initial_stream_window_size,
8887
initial_connection_window_size,
8988
}) => {
90-
srv.http2_initial_stream_window_size(initial_stream_window_size)
91-
.http2_initial_connection_window_size(initial_connection_window_size);
89+
http2
90+
.initial_stream_window_size(initial_stream_window_size)
91+
.initial_connection_window_size(initial_connection_window_size);
9292
}
9393
}
9494

9595
// Configure HTTP/2 PING frames
9696
if let Some(h2::KeepAlive { timeout, interval }) = keep_alive {
97-
srv.http2_keep_alive_timeout(timeout)
98-
.http2_keep_alive_interval(interval);
97+
http2
98+
.keep_alive_timeout(timeout)
99+
.keep_alive_interval(interval);
99100
}
100101

101-
srv.http2_max_concurrent_streams(max_concurrent_streams)
102-
.http2_max_frame_size(max_frame_size)
103-
.http2_max_pending_accept_reset_streams(max_pending_accept_reset_streams);
102+
http2
103+
.max_concurrent_streams(max_concurrent_streams)
104+
.max_frame_size(max_frame_size)
105+
.max_pending_accept_reset_streams(max_pending_accept_reset_streams);
104106
if let Some(sz) = max_header_list_size {
105-
srv.http2_max_header_list_size(sz);
107+
http2.max_header_list_size(sz);
106108
}
107109
if let Some(sz) = max_send_buf_size {
108-
srv.http2_max_send_buf_size(sz);
110+
http2.max_send_buf_size(sz);
109111
}
110112

111113
debug!(?version, "Creating HTTP service");
@@ -114,7 +116,8 @@ where
114116
inner,
115117
version,
116118
drain,
117-
server: srv,
119+
http1: hyper::server::conn::http1::Builder::new(),
120+
http2,
118121
}
119122
}
120123
}
@@ -142,7 +145,8 @@ where
142145
fn call(&mut self, io: I) -> Self::Future {
143146
let version = self.version;
144147
let drain = self.drain.clone();
145-
let mut server = self.server.clone();
148+
let http1 = self.http1.clone();
149+
let http2 = self.http2.clone();
146150

147151
let res = io.peer_addr().map(|pa| {
148152
let (handle, closed) = ClientHandle::new(pa);
@@ -162,10 +166,7 @@ where
162166
BoxRequest::new(svc),
163167
drain.clone(),
164168
);
165-
let mut conn = server
166-
.http1_only(true)
167-
.serve_connection(io, svc)
168-
.with_upgrades();
169+
let mut conn = http1.serve_connection(io, svc).with_upgrades();
169170

170171
tokio::select! {
171172
res = &mut conn => {
@@ -186,9 +187,7 @@ where
186187
}
187188

188189
Version::H2 => {
189-
let mut conn = server
190-
.http2_only(true)
191-
.serve_connection(io, BoxRequest::new(svc));
190+
let mut conn = http2.serve_connection(io, BoxRequest::new(svc));
192191

193192
tokio::select! {
194193
res = &mut conn => {

0 commit comments

Comments
 (0)