Skip to content

Commit

Permalink
[PENDING lambda-http update] Migrate to latest deps (axum, hyper, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcking committed Dec 14, 2023
1 parent 1d62c39 commit 64c8327
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { git = "https://github.com/awslabs/aws-lambda-rust-runtime", branch = "hyper1_upgrade" }
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",
Expand Down
9 changes: 4 additions & 5 deletions examples/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<lambda_http::Body> = match std::str::from_utf8(bytes) {
Ok(s) => hyper::Response::from_parts(parts, s.into()),
Expand Down

0 comments on commit 64c8327

Please sign in to comment.