Skip to content

Commit 07430f1

Browse files
calaverasimbleau
andauthored
Hyper 1 upgrade (#749)
* chore: update hyper/http * chore: update hyper with legacy * Create new workspace dependencies. This makes tracking versions across packages easier. Signed-off-by: David Calavera <david.calavera@gmail.com> * Bring helpers to work with Hyper 1. Copy some of the utils that Axum created to support Hyper 1. Signed-off-by: David Calavera <david.calavera@gmail.com> * Upgrade lambda_runtime to Hyper 1. Signed-off-by: David Calavera <david.calavera@gmail.com> * Upgrade lambda_http to Hyper 1. Signed-off-by: David Calavera <david.calavera@gmail.com> * Update Axum examples to version 0.7. Signed-off-by: David Calavera <david.calavera@gmail.com> * Make extensions compile. Switch to use hyper::service::service_fn definitions. Implement new Hyper's polling loop for http connections. Signed-off-by: David Calavera <david.calavera@gmail.com> * Update tower-http to make cors example work. Signed-off-by: David Calavera <david.calavera@gmail.com> * Update tower-http to make tower-trace example work. Signed-off-by: David Calavera <david.calavera@gmail.com> * Make less copies of extension services. Signed-off-by: David Calavera <david.calavera@gmail.com> * Bring Body::channel implementation from Hyper Given the lack of a public implementation anymore, we don't have other choice but copying Hyper's private implementation. Signed-off-by: David Calavera <david.calavera@gmail.com> * Organize more dependencies. Signed-off-by: David Calavera <david.calavera@gmail.com> * Cleanup commented code. Signed-off-by: David Calavera <david.calavera@gmail.com> * Cleanup unused dependencies. Signed-off-by: David Calavera <david.calavera@gmail.com> * Introduce a module to group all streaming functionality. This makes the streaming functionallity more concise. It aliases other functionality to keep backwards compatibility. Signed-off-by: David Calavera <david.calavera@gmail.com> * Remove unnecesary loop. Signed-off-by: David Calavera <david.calavera@gmail.com> * Don't re-export `lambda_runtime_api_client::body`. Signed-off-by: David Calavera <david.calavera@gmail.com> --------- Signed-off-by: David Calavera <david.calavera@gmail.com> Co-authored-by: Spencer C. Imbleau <spencer@imbleau.com>
1 parent fb86ebc commit 07430f1

File tree

34 files changed

+921
-264
lines changed

34 files changed

+921
-264
lines changed

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@ members = [
1010
]
1111

1212
exclude = ["examples"]
13+
14+
[workspace.dependencies]
15+
base64 = "0.21"
16+
bytes = "1"
17+
futures = "0.3"
18+
futures-channel = "0.3"
19+
futures-util = "0.3"
20+
http = "1.0"
21+
http-body = "1.0"
22+
http-body-util = "0.1"
23+
http-serde = "2.0"
24+
hyper = "1.0"
25+
hyper-util = "0.1.1"
26+
pin-project-lite = "0.2"
27+
tower = "0.4"
28+
tower-service = "0.3"

examples/basic-streaming-response/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
hyper = { version = "0.14", features = [
10-
"http1",
11-
"client",
12-
"stream",
13-
] }
149
lambda_runtime = { path = "../../lambda-runtime" }
1510
tokio = { version = "1", features = ["macros"] }
1611
tracing = { version = "0.1", features = ["log"] }

examples/basic-streaming-response/src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
use hyper::body::Body;
2-
use lambda_runtime::{service_fn, Error, LambdaEvent, StreamResponse};
1+
use lambda_runtime::{
2+
service_fn,
3+
streaming::{channel, Body, Response},
4+
Error, LambdaEvent,
5+
};
36
use serde_json::Value;
47
use std::{thread, time::Duration};
58

6-
async fn func(_event: LambdaEvent<Value>) -> Result<StreamResponse<Body>, Error> {
9+
async fn func(_event: LambdaEvent<Value>) -> Result<Response<Body>, Error> {
710
let messages = vec!["Hello", "world", "from", "Lambda!"];
811

9-
let (mut tx, rx) = Body::channel();
12+
let (mut tx, rx) = channel();
1013

1114
tokio::spawn(async move {
1215
for message in messages.iter() {
@@ -15,10 +18,7 @@ async fn func(_event: LambdaEvent<Value>) -> Result<StreamResponse<Body>, Error>
1518
}
1619
});
1720

18-
Ok(StreamResponse {
19-
metadata_prelude: Default::default(),
20-
stream: rx,
21-
})
21+
Ok(Response::from(rx))
2222
}
2323

2424
#[tokio::main]

examples/http-axum-diesel-ssl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ edition = "2021"
1111
# and it will keep the alphabetic ordering for you.
1212

1313
[dependencies]
14-
axum = "0.6.4"
14+
axum = "0.7"
1515
bb8 = "0.8.0"
1616
diesel = "2.0.3"
1717
diesel-async = { version = "0.2.1", features = ["postgres", "bb8"] }

examples/http-axum-diesel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ edition = "2021"
1111
# and it will keep the alphabetic ordering for you.
1212

1313
[dependencies]
14-
axum = "0.6.4"
14+
axum = "0.7"
1515
bb8 = "0.8.0"
1616
diesel = "2.0.3"
1717
diesel-async = { version = "0.2.1", features = ["postgres", "bb8"] }

examples/http-axum/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ edition = "2021"
1111
# and it will keep the alphabetic ordering for you.
1212

1313
[dependencies]
14+
axum = "0.7"
1415
lambda_http = { path = "../../lambda-http" }
1516
lambda_runtime = { path = "../../lambda-runtime" }
17+
serde_json = "1.0"
1618
tokio = { version = "1", features = ["macros"] }
1719
tracing = { version = "0.1", features = ["log"] }
1820
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19-
20-
axum = "0.6.4"
21-
serde_json = "1.0"

examples/http-cors/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2021"
1414
lambda_http = { path = "../../lambda-http" }
1515
lambda_runtime = { path = "../../lambda-runtime" }
1616
tokio = { version = "1", features = ["macros"] }
17-
tower-http = { version = "0.3.3", features = ["cors"] }
17+
tower-http = { version = "0.5", features = ["cors"] }
1818
tracing = { version = "0.1", features = ["log"] }
1919
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
2020

examples/http-tower-trace/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ edition = "2021"
1414
lambda_http = { path = "../../lambda-http" }
1515
lambda_runtime = "0.5.1"
1616
tokio = { version = "1", features = ["macros"] }
17-
tower-http = { version = "0.3.4", features = ["trace"] }
17+
tower-http = { version = "0.5", features = ["trace"] }
1818
tracing = { version = "0.1", features = ["log"] }
1919
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }

lambda-events/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ categories = ["api-bindings", "encoding", "web-programming"]
1616
edition = "2021"
1717

1818
[dependencies]
19-
base64 = "0.21"
20-
http = { version = "0.2", optional = true }
21-
http-body = { version = "0.4", optional = true }
22-
http-serde = { version = "^1", optional = true }
23-
serde = { version = "^1", features = ["derive"] }
24-
serde_with = { version = "^3", features = ["json"], optional = true }
25-
serde_json = "^1"
26-
serde_dynamo = { version = "^4.1", optional = true }
27-
bytes = { version = "1", features = ["serde"], optional = true }
19+
base64 = { workspace = true }
20+
bytes = { workspace = true, features = ["serde"], optional = true }
2821
chrono = { version = "0.4.31", default-features = false, features = [
2922
"clock",
3023
"serde",
3124
"std",
3225
], optional = true }
26+
flate2 = { version = "1.0.24", optional = true }
27+
http = { workspace = true, optional = true }
28+
http-body = { workspace = true, optional = true }
29+
http-serde = { workspace = true, optional = true }
3330
query_map = { version = "^0.7", features = [
3431
"serde",
3532
"url-query",
3633
], optional = true }
37-
flate2 = { version = "1.0.24", optional = true }
34+
serde = { version = "^1", features = ["derive"] }
35+
serde_with = { version = "^3", features = ["json"], optional = true }
36+
serde_json = "^1"
37+
serde_dynamo = { version = "^4.1", optional = true }
3838

3939
[features]
4040
default = [

lambda-events/src/encodings/http.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,6 @@ impl HttpBody for Body {
218218
type Data = Bytes;
219219
type Error = super::Error;
220220

221-
fn poll_data(
222-
self: Pin<&mut Self>,
223-
_cx: &mut std::task::Context<'_>,
224-
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
225-
let body = take(self.get_mut());
226-
Poll::Ready(match body {
227-
Body::Empty => None,
228-
Body::Text(s) => Some(Ok(s.into())),
229-
Body::Binary(b) => Some(Ok(b.into())),
230-
})
231-
}
232-
233-
fn poll_trailers(
234-
self: Pin<&mut Self>,
235-
_cx: &mut std::task::Context<'_>,
236-
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
237-
Poll::Ready(Ok(None))
238-
}
239-
240221
fn is_end_stream(&self) -> bool {
241222
matches!(self, Body::Empty)
242223
}
@@ -248,6 +229,18 @@ impl HttpBody for Body {
248229
Body::Binary(ref b) => SizeHint::with_exact(b.len() as u64),
249230
}
250231
}
232+
233+
fn poll_frame(
234+
self: Pin<&mut Self>,
235+
_cx: &mut std::task::Context<'_>,
236+
) -> Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> {
237+
let body = take(self.get_mut());
238+
Poll::Ready(match body {
239+
Body::Empty => None,
240+
Body::Text(s) => Some(Ok(http_body::Frame::data(s.into()))),
241+
Body::Binary(b) => Some(Ok(http_body::Frame::data(b.into()))),
242+
})
243+
}
251244
}
252245

253246
#[cfg(test)]

lambda-events/src/event/bedrock_agent_runtime/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ pub struct Agent {
8282

8383
#[cfg(test)]
8484
mod tests {
85-
use serde_json;
86-
8785
#[test]
8886
#[cfg(feature = "bedrock-agent-runtime")]
8987
fn example_bedrock_agent__runtime_event() {

lambda-extension/Cargo.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ readme = "README.md"
1515

1616
[dependencies]
1717
async-stream = "0.3"
18-
bytes = "1.0"
18+
bytes = { workspace = true }
1919
chrono = { version = "0.4", features = ["serde"] }
20-
http = "0.2"
21-
hyper = { version = "0.14.20", features = ["http1", "client", "server", "stream", "runtime"] }
20+
http = { workspace = true }
21+
http-body-util = { workspace = true }
22+
hyper = { workspace = true, features = ["http1", "client", "server"] }
23+
hyper-util = { workspace = true }
2224
lambda_runtime_api_client = { version = "0.8", path = "../lambda-runtime-api-client" }
2325
serde = { version = "1", features = ["derive"] }
2426
serde_json = "^1"
2527
tracing = { version = "0.1", features = ["log"] }
26-
tokio = { version = "1.0", features = ["macros", "io-util", "sync", "rt-multi-thread"] }
28+
tokio = { version = "1.0", features = [
29+
"macros",
30+
"io-util",
31+
"sync",
32+
"rt-multi-thread",
33+
] }
2734
tokio-stream = "0.1.2"
2835
tower = { version = "0.4", features = ["make", "util"] }
29-

lambda-extension/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Error type that extensions may result in
2-
pub type Error = lambda_runtime_api_client::Error;
2+
pub type Error = lambda_runtime_api_client::BoxError;
33

44
/// Simple error that encapsulates human readable descriptions
55
#[derive(Clone, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)