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

Migrate to latest deps (axum, hyper, etc.) #8

Merged
merged 2 commits into from
Dec 22, 2023
Merged
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
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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",
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