Skip to content

Commit f3812cf

Browse files
committed
refactor(app): update deprecated hyper body calls
hyper 0.14.x provided a collection of interfaces related to collecting and aggregating request and response bodies, which were deprecated and removed in the 1.x major release. this commit updates calls to `hyper::body::to_bytes(..)` and `hyper::body::aggregate(..)`. for now, `http_body::Body` is used, but we can use `http_body_util::BodyExt` once we've bumped our hyper dependency to the 1.x major release. for more information, see: * linkerd/linkerd2#8733 * hyperium/hyper#2840 * hyperium/hyper#3020 Signed-off-by: katelyn martin <kate@buoyant.io>
1 parent c10b21e commit f3812cf

File tree

10 files changed

+49
-36
lines changed

10 files changed

+49
-36
lines changed

linkerd/app/admin/src/server/log/level.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ where
2121
}
2222

2323
http::Method::PUT => {
24-
#[allow(deprecated)] // linkerd/linkerd2#8733
25-
let body = hyper::body::aggregate(req.into_body())
24+
let body = req
25+
.into_body()
26+
.collect()
2627
.await
27-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
28+
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
29+
.aggregate();
2830
match level.set_from(body.chunk()) {
2931
Ok(_) => mk_rsp(StatusCode::NO_CONTENT, Body::empty()),
3032
Err(error) => {

linkerd/app/admin/src/server/log/stream.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ where
5252
// If the request is a QUERY, use the request body
5353
method if method.as_str() == "QUERY" => {
5454
// TODO(eliza): validate that the request has a content-length...
55-
#[allow(deprecated)] // linkerd/linkerd2#8733
5655
let body = recover!(
57-
hyper::body::aggregate(req.into_body())
56+
http_body::Body::collect(req.into_body())
5857
.await
59-
.map_err(Into::into),
58+
.map_err(Into::into)
59+
.map(http_body::Collected::aggregate),
6060
"Reading log stream request body",
6161
StatusCode::BAD_REQUEST
6262
);

linkerd/app/integration/src/tap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ where
209209
// just can't prove it.
210210
let req = futures::executor::block_on(async move {
211211
let (parts, body) = req.into_parts();
212-
#[allow(deprecated)] // linkerd/linkerd2#8733
213-
let body = match hyper::body::to_bytes(body).await {
212+
let body = match body.collect().await.map(http_body::Collected::to_bytes) {
214213
Ok(body) => body,
215214
Err(_) => unreachable!("body should not fail"),
216215
};

linkerd/app/integration/src/tests/discovery.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,15 @@ mod http2 {
482482
let res = fut.await.expect("beta response");
483483
assert_eq!(res.status(), http::StatusCode::OK);
484484

485-
#[allow(deprecated)] // linkerd/linkerd2#8733
486-
let body = String::from_utf8(
487-
hyper::body::to_bytes(res.into_body())
485+
let body = {
486+
let body = res.into_body();
487+
let body = http_body::Body::collect(body)
488488
.await
489489
.unwrap()
490-
.to_vec(),
491-
)
492-
.unwrap();
490+
.to_bytes()
491+
.to_vec();
492+
String::from_utf8(body).unwrap()
493+
};
493494
assert_eq!(body, "beta");
494495
}
495496
}

linkerd/app/integration/src/tests/profiles.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ impl TestBuilder {
129129
async move {
130130
// Read the entire body before responding, so that the
131131
// client doesn't fail when writing it out.
132-
#[allow(deprecated)] // linkerd/linkerd2#8733
133-
let _body = hyper::body::to_bytes(req.into_body()).await;
134-
tracing::debug!(body = ?_body.as_ref().map(|body| body.len()), "recieved body");
132+
let body = http_body::Body::collect(req.into_body())
133+
.await
134+
.map(http_body::Collected::to_bytes);
135+
let bytes = body.as_ref().map(Bytes::len);
136+
tracing::debug!(?bytes, "recieved body");
135137
Ok::<_, Error>(if fail {
136138
Response::builder().status(533).body("nope".into()).unwrap()
137139
} else {

linkerd/app/integration/src/tests/shutdown.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ async fn h2_exercise_goaways_connections() {
4848

4949
let bodies = resps
5050
.into_iter()
51-
.map(
52-
#[allow(deprecated)] // linkerd/linkerd2#8733
53-
|resp| {
54-
hyper::body::aggregate(resp.into_body())
55-
// Make sure the bodies weren't cut off
56-
.map_ok(|buf| assert_eq!(buf.remaining(), RESPONSE_SIZE))
57-
},
58-
)
51+
.map(Response::into_body)
52+
.map(|body| {
53+
http_body::Body::collect(body)
54+
.map_ok(http_body::Collected::aggregate)
55+
// Make sure the bodies weren't cut off
56+
.map_ok(|buf| assert_eq!(buf.remaining(), RESPONSE_SIZE))
57+
})
5958
.collect::<Vec<_>>();
6059

6160
// See that the proxy gives us all the bodies.

linkerd/app/integration/src/tests/tap.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,12 @@ async fn grpc_headers_end() {
253253
.unwrap();
254254
assert_eq!(res.status(), 200);
255255
assert_eq!(res.headers()["grpc-status"], "1");
256-
#[allow(deprecated)] // linkerd/linkerd2#8733
257-
let bytes = hyper::body::to_bytes(res.into_body()).await.unwrap().len();
256+
let body = res.into_body();
257+
let bytes = http_body::Body::collect(body)
258+
.await
259+
.unwrap()
260+
.to_bytes()
261+
.len();
258262
assert_eq!(bytes, 0);
259263

260264
let event = events.skip(2).next().await.expect("2nd").expect("stream");

linkerd/app/integration/src/tests/telemetry.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1304,10 +1304,13 @@ async fn metrics_compression() {
13041304
);
13051305
}
13061306

1307-
#[allow(deprecated)] // linkerd/linkerd2#8733
1308-
let mut body = hyper::body::aggregate(resp.into_body())
1309-
.await
1310-
.expect("response body concat");
1307+
let mut body = {
1308+
let body = resp.into_body();
1309+
http_body::Body::collect(body)
1310+
.await
1311+
.expect("response body concat")
1312+
.aggregate()
1313+
};
13111314
let mut decoder = flate2::read::GzDecoder::new(std::io::Cursor::new(
13121315
body.copy_to_bytes(body.remaining()),
13131316
));

linkerd/app/outbound/src/http/logical/tests.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ async fn assert_rsp<T: std::fmt::Debug>(
144144
{
145145
let rsp = rsp.await.expect("response must not fail");
146146
assert_eq!(rsp.status(), status, "expected status code to be {status}");
147-
#[allow(deprecated)] // linkerd/linkerd2#8733
148-
let body = hyper::body::to_bytes(rsp.into_body())
147+
let body = rsp
148+
.into_body()
149+
.collect()
149150
.await
150-
.expect("body must not fail");
151+
.expect("body must not fail")
152+
.to_bytes();
151153
assert_eq!(body, expected_body, "expected body to be {expected_body:?}");
152154
}
153155

linkerd/app/test/src/http_util.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ where
121121
T: HttpBody,
122122
T::Error: Into<Error>,
123123
{
124-
#[allow(deprecated)] // linkerd/linkerd2#8733
125-
let body = hyper::body::to_bytes(body)
124+
let body = body
125+
.collect()
126126
.await
127+
.map(http_body::Collected::to_bytes)
127128
.map_err(ContextError::ctx("HTTP response body stream failed"))?;
128129
let body = std::str::from_utf8(&body[..])
129130
.map_err(ContextError::ctx("converting body to string failed"))?

0 commit comments

Comments
 (0)