From e4356c932d26d44981425980566ab0c751fec273 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Wed, 13 Dec 2023 17:49:00 -0800 Subject: [PATCH 1/2] Migrate to latest deps (axum, hyper, lambda-http) --- Cargo.toml | 10 ++++++---- examples/main.rs | 9 ++++----- src/lib.rs | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 87087de..2f69fd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,17 +13,19 @@ keywords = ["axum", "lambda", "tower", "aws"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axum = "0.6" -lambda_http = "0.8" -hyper = "0.14" +axum = "0.7.2" +lambda_http = "0.9.0" +hyper = "1.0.1" bytes = "1.5" http = "1" tower = "0.4" tower-service = "0.3" +futures-util = "0.3.29" +http-body-util = "0.1.0" [dev-dependencies] tokio = { version = "1.0", features = ["rt"] } -tower-http = { version = "0.4", features = [ +tower-http = { version = "0.5.0", features = [ "cors", "compression-gzip", "compression-deflate", diff --git a/examples/main.rs b/examples/main.rs index 6f9bf17..58c21d9 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -1,3 +1,4 @@ +use axum::body::Body; use axum::extract::State; use axum::http::header::{ACCEPT, ACCEPT_ENCODING, AUTHORIZATION, CONTENT_TYPE, ORIGIN}; use axum::response::IntoResponse; @@ -6,7 +7,7 @@ use axum::{ Json, Router, }; use hyper::Request; -use hyper::{Body, StatusCode}; +use hyper::StatusCode; use serde::{Deserialize, Serialize}; use std::sync::{Arc, Mutex}; use tower_http::{compression::CompressionLayer, cors::CorsLayer, trace::TraceLayer}; @@ -70,10 +71,8 @@ async fn main() { #[cfg(debug_assertions)] { let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3000)); - axum::Server::bind(&addr) - .serve(app.into_make_service()) - .await - .unwrap(); + let listener = tokio::net::TcpListener::bind(addr).await.unwrap(); + axum::serve(listener, app).await.unwrap(); } // If we compile in release mode, use the Lambda Runtime diff --git a/src/lib.rs b/src/lib.rs index 5f15100..c8b47cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ use axum::response::IntoResponse; +use http_body_util::BodyExt; use lambda_http::RequestExt; use std::{future::Future, pin::Pin}; use tower::Layer; @@ -85,7 +86,7 @@ where let fut = async move { let resp = fut.await?; let (parts, body) = resp.into_response().into_parts(); - let bytes = hyper::body::to_bytes(body).await?; + let bytes = body.into_data_stream().collect().await?.to_bytes(); let bytes: &[u8] = &bytes; let resp: hyper::Response = match std::str::from_utf8(bytes) { Ok(s) => hyper::Response::from_parts(parts, s.into()), From bd4e9a0d847352a8c7989514d5df0841a2ac4289 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Thu, 21 Dec 2023 22:55:05 -0500 Subject: [PATCH 2/2] Bump minor version The upgrade to hyper v1 is backwards incompatible. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2f69fd5..3279416 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axum-aws-lambda" -version = "0.5.1" +version = "0.6.0" edition = "2021" authors = ["Michael Lazear"] description = "Tower Layer for compatibility between Axum and AWS Lambda Runtime"