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

Prepare for Hyper 1.0.0 Upgrade: Enable Deprecated Features and Resolve Deprecations #1938

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
57 changes: 30 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
[workspace]
resolver = "2"
members = [
"admin",
"api-client",
"auth",
"backends",
"cargo-shuttle",
"codegen",
"common",
"common-tests",
"deployer",
"gateway",
"logger",
"proto",
"provisioner",
"resource-recorder",
"runtime",
"service",
]
exclude = [
"examples",
"resources",
"services",
"admin",
"api-client",
"auth",
"backends",
"cargo-shuttle",
"codegen",
"common",
"common-tests",
"deployer",
"gateway",
"logger",
"proto",
"provisioner",
"resource-recorder",
"runtime",
"service",
]
exclude = ["examples", "resources", "services"]

[workspace.package]
version = "0.49.0"
Expand Down Expand Up @@ -62,15 +58,20 @@ headers = "0.3.8"
home = "0.5.4"
http = "0.2.8"
http-body = "0.4.5"
hyper = "0.14.23"
hyper = { version = "0.14.23", features = ["backports", "deprecated"] }
# not great, but waiting for WebSocket changes to be merged
hyper-reverse-proxy = { git = "https://github.com/chesedo/hyper-reverse-proxy", branch = "bug/host_header" }
Comment on lines 62 to 63
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using a git dependency for hyper-reverse-proxy could cause build instability. Consider pinning to a specific commit hash rather than branch, or better yet, wait for the WebSocket changes to be merged and use a released version.

jsonwebtoken = "9.0.0"
once_cell = "1.16.0"
opentelemetry = "0.21.0"
opentelemetry_sdk = { version = "0.21.0", features = ["rt-tokio", "logs"] }
opentelemetry-http = "0.10.0"
opentelemetry-otlp = { version = "0.14.0", features = ["logs", "http-proto", "reqwest-client", "reqwest-rustls"] }
opentelemetry-otlp = { version = "0.14.0", features = [
"logs",
"http-proto",
"reqwest-client",
"reqwest-rustls",
] }
opentelemetry-proto = "0.4.0"
opentelemetry-contrib = { version = "0.4.0", features = ["datadog"] }
opentelemetry-appender-tracing = "0.2.0"
Expand All @@ -81,7 +82,9 @@ pretty_assertions = "1.3.0"
prost = "0.12.1"
prost-types = "0.12.1"
rand = "0.8.5"
reqwest = { version = "0.11.13", default-features = false, features = ["rustls-tls"] }
reqwest = { version = "0.11.13", default-features = false, features = [
"rustls-tls",
] }
ring = "0.17.4"
rmp-serde = "1.1.1"
semver = { version = "1.0.17", features = ["serde"] }
Expand All @@ -97,7 +100,7 @@ thiserror = "2"
tokio = "1.22.0"
tokio-stream = "0.1.11"
tokio-tungstenite = { version = "0.20.1", features = [
"rustls-tls-webpki-roots",
"rustls-tls-webpki-roots",
] }
tokio-util = "0.7.10"
toml = "0.8.2"
Expand All @@ -108,8 +111,8 @@ tower-http = { version = "0.4.0", features = ["trace"] }
tracing = { version = "0.1.37", default-features = false }
tracing-opentelemetry = "0.22.0"
tracing-subscriber = { version = "0.3.16", default-features = false, features = [
"registry",
"json",
"registry",
"json",
] }
typeshare = "1.0.3"
ttl_cache = "0.5.1"
Expand Down
6 changes: 5 additions & 1 deletion auth/tests/api/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ mod needs_docker {
let response = app.post_user("test-user-basic", "basic").await;
assert_eq!(response.status(), StatusCode::OK);
// Extract the API key from the response so we can use it in a future request.
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider handling the unwrap() case more gracefully since this is a test that could fail

.to_bytes();

let user: Value = serde_json::from_slice(&body).unwrap();
let basic_user_key = user["key"].as_str().unwrap();

Expand Down
15 changes: 12 additions & 3 deletions auth/tests/api/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ impl TestApp {

pub async fn get_user_typed(&self, user_id: &str) -> user::UserResponse {
let response = self.get_user(user_id).await;
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

serde_json::from_slice(&body).unwrap()
}
Expand Down Expand Up @@ -174,7 +177,10 @@ impl TestApp {
}

pub async fn claim_from_response(&self, res: Response) -> Claim {
let body = hyper::body::to_bytes(res.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(res.into_body())
.await
.unwrap()
.to_bytes();
let convert: Value = serde_json::from_slice(&body).unwrap();
let token = convert["token"].as_str().unwrap();

Expand All @@ -188,7 +194,10 @@ impl TestApp {

assert_eq!(response.status(), StatusCode::OK);

let public_key = hyper::body::to_bytes(response.into_body()).await.unwrap();
let public_key = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
Comment on lines +197 to +200
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider extracting body collection logic into a helper method to avoid repetition


Claim::from_token(token, &public_key).unwrap()
}
Expand Down
63 changes: 51 additions & 12 deletions auth/tests/api/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ mod needs_docker {

assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
Comment on lines +49 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: This pattern is repeated throughout the file. Consider extracting this common body collection logic into a helper function to reduce duplication and make future API changes easier.

let user: user::UserResponse = serde_json::from_slice(&body).unwrap();
let user_id1 = user.id.clone();

Expand All @@ -60,7 +63,10 @@ mod needs_docker {

assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
let user: user::UserResponse = serde_json::from_slice(&body).unwrap();
let user_id2 = user.id.clone();

Expand Down Expand Up @@ -88,7 +94,11 @@ mod needs_docker {

assert_eq!(response.status(), StatusCode::OK);

let post_body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let post_body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

let user: user::UserResponse = serde_json::from_slice(&post_body).unwrap();
let user_id = user.id;

Expand Down Expand Up @@ -123,7 +133,10 @@ mod needs_docker {

assert_eq!(response.status(), StatusCode::OK);

let get_body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let get_body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

assert_eq!(post_body, get_body);
}
Expand All @@ -137,7 +150,10 @@ mod needs_docker {

assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
let user: user::UserResponse = serde_json::from_slice(&body).unwrap();
let user_id = &user.id;

Expand All @@ -160,7 +176,10 @@ mod needs_docker {
.await;

assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
let pro_user: user::UserResponse = serde_json::from_slice(&body).unwrap();

assert_eq!(user.name, pro_user.name);
Expand All @@ -187,7 +206,10 @@ mod needs_docker {
// POST user first so one exists in the database.
let response = app.post_user("test-user", "basic").await;
assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
let user: user::UserResponse = serde_json::from_slice(&body).unwrap();
let user_id = &user.id;

Expand All @@ -214,7 +236,10 @@ mod needs_docker {

assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
let actual_user: user::UserResponse = serde_json::from_slice(&body).unwrap();

assert_eq!(actual_user.account_tier, AccountTier::PendingPaymentPro);
Expand All @@ -238,7 +263,10 @@ mod needs_docker {
assert_eq!(response.status(), StatusCode::OK);

// Extract the API key from the response so we can use it in a future request.
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
let user: user::UserResponse = serde_json::from_slice(&body).unwrap();
let user_id = &user.id;
let basic_user_key = &user.key;
Expand Down Expand Up @@ -330,7 +358,10 @@ mod needs_docker {
// Create user with basic tier
let response = app.post_user("test-user", "basic").await;
assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
let user: user::UserResponse = serde_json::from_slice(&body).unwrap();
let user_id = &user.id;

Expand Down Expand Up @@ -364,7 +395,11 @@ mod needs_docker {

assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

let user: user::UserResponse = serde_json::from_slice(&body).unwrap();
assert_eq!(user.account_tier, AccountTier::CancelledPro);

Expand All @@ -379,7 +414,11 @@ mod needs_docker {
.await;
assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

let user: user::UserResponse = serde_json::from_slice(&body).unwrap();

assert_eq!(user.account_tier, AccountTier::Basic);
Expand Down
7 changes: 5 additions & 2 deletions backends/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl PublicKeyFn for AuthPublicKey {
});

let res = client.request(request.body(Body::empty())?).await?;
let buf = body::to_bytes(res).await?;
let buf = body::HttpBody::collect(res).await?.to_bytes();

trace!("inserting public key from auth service into cache");
self.cache_manager.insert(
Expand Down Expand Up @@ -637,7 +637,10 @@ mod tests {
.unwrap();

assert_eq!(response.status(), StatusCode::OK);
let body = body::to_bytes(response.into_body()).await.unwrap();
let body = body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

assert_eq!(&body[..], b"Hello, ferries");
}
Expand Down
22 changes: 18 additions & 4 deletions backends/src/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,45 @@ mod tests {
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

assert_eq!(&body[..], b"test123");

let response = app
.call(Request::get("/__test123").body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
Comment on lines +112 to +115
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider extracting this repeated body collection pattern into a helper function to reduce duplication


assert!(&body[..].starts_with(br#"{"message":"Invalid project name"#));

let response = app
.call(Request::get("/test123/123").body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
assert_eq!(&body[..], b"test123 123");

let response = app
.call(Request::get("/test123/asdf").body(Body::empty()).unwrap())
.await
.unwrap();
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
assert!(&body[..].starts_with(br#"{"message":"Invalid URL"#));
}
}
11 changes: 8 additions & 3 deletions backends/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ mod tests {
body::Body, extract::Path, http::Request, http::StatusCode, middleware::from_extractor,
response::IntoResponse, routing::get, Router,
};
use hyper::body;
use tower::ServiceExt;
use tracing::field;
use tracing_fluent_assertions::{AssertionRegistry, AssertionsLayer};
Expand Down Expand Up @@ -269,7 +268,10 @@ mod tests {

assert_eq!(response.status(), StatusCode::OK);

let body = body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();
Comment on lines +271 to +274
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: This change replaces deprecated body::to_bytes() with newer API, but consider handling the unwrap() to avoid potential panics in tests


assert_eq!(&body[..], b"hello");
request_span.assert();
Expand Down Expand Up @@ -315,7 +317,10 @@ mod tests {

assert_eq!(response.status(), StatusCode::OK);

let body = body::to_bytes(response.into_body()).await.unwrap();
let body = hyper::body::HttpBody::collect(response.into_body())
.await
.unwrap()
.to_bytes();

assert_eq!(&body[..], b"hello ferries");
request_span.assert();
Expand Down
Loading