Skip to content
Closed
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
6 changes: 3 additions & 3 deletions lambda-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ edition = "2021"

[dependencies]
base64 = "0.21"
http = { version = "0.2", optional = true }
http-body = { version = "0.4", optional = true }
http-serde = { version = "^1", optional = true }
http = { version = "1.0", optional = true }
http-body = { version = "1.0", optional = true }
http-serde = { version = "2.0", optional = true }
serde = { version = "^1", features = ["derive"] }
serde_with = { version = "^3", features = ["json"], optional = true }
serde_json = "^1"
Expand Down
31 changes: 12 additions & 19 deletions lambda-events/src/encodings/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,6 @@ impl HttpBody for Body {
type Data = Bytes;
type Error = super::Error;

fn poll_data(
self: Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
let body = take(self.get_mut());
Poll::Ready(match body {
Body::Empty => None,
Body::Text(s) => Some(Ok(s.into())),
Body::Binary(b) => Some(Ok(b.into())),
})
}

fn poll_trailers(
self: Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
Poll::Ready(Ok(None))
}

fn is_end_stream(&self) -> bool {
matches!(self, Body::Empty)
}
Expand All @@ -248,6 +229,18 @@ impl HttpBody for Body {
Body::Binary(ref b) => SizeHint::with_exact(b.len() as u64),
}
}

fn poll_frame(
self: Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> Poll<Option<Result<http_body::Frame<Self::Data>, Self::Error>>> {
let body = take(self.get_mut());
Poll::Ready(match body {
Body::Empty => None,
Body::Text(s) => Some(Ok(http_body::Frame::data(s.into()))),
Body::Binary(b) => Some(Ok(http_body::Frame::data(b.into()))),
})
}
}

#[cfg(test)]
Expand Down
12 changes: 8 additions & 4 deletions lambda-extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ readme = "README.md"
async-stream = "0.3"
bytes = "1.0"
chrono = { version = "0.4", features = ["serde"] }
http = "0.2"
hyper = { version = "0.14.20", features = ["http1", "client", "server", "stream", "runtime"] }
http = "1.0"
hyper = { version = "1.0", features = ["http1", "client", "server"] }
lambda_runtime_api_client = { version = "0.8", path = "../lambda-runtime-api-client" }
serde = { version = "1", features = ["derive"] }
serde_json = "^1"
tracing = { version = "0.1", features = ["log"] }
tokio = { version = "1.0", features = ["macros", "io-util", "sync", "rt-multi-thread"] }
tokio = { version = "1.0", features = [
"macros",
"io-util",
"sync",
"rt-multi-thread",
] }
tokio-stream = "0.1.2"
tower = { version = "0.4", features = ["make", "util"] }

6 changes: 3 additions & 3 deletions lambda-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ alb = []
base64 = "0.21"
bytes = "1.4"
futures = "0.3"
http = "0.2"
http-body = "0.4"
hyper = "0.14"
http = "1.0"
http-body = "1.0"
hyper = "1.0"
lambda_runtime = { path = "../lambda-runtime", version = "0.8.3" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
14 changes: 11 additions & 3 deletions lambda-runtime-api-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.8.0"
edition = "2021"
authors = [
"David Calavera <dcalaver@amazon.com>",
"Harold Sun <sunhua@amazon.com>"
"Harold Sun <sunhua@amazon.com>",
]
description = "AWS Lambda Runtime interaction API"
license = "Apache-2.0"
Expand All @@ -14,7 +14,15 @@ keywords = ["AWS", "Lambda", "API"]
readme = "README.md"

[dependencies]
http = "0.2"
hyper = { version = "0.14.20", features = ["http1", "client", "stream", "tcp"] }
http = "1.0"
http-body = "1.0"
http-body-util = "0.1"
hyper = { version = "1.0", features = ["http1", "client"] }
hyper-util = { version = "0.1.1", features = [
"client",
"client-legacy",
"http1",
"tokio",
] }
tower-service = "0.3"
tokio = { version = "1.0", features = ["io-util"] }
25 changes: 12 additions & 13 deletions lambda-runtime-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
//! This crate includes a base HTTP client to interact with
//! the AWS Lambda Runtime API.
use http::{uri::PathAndQuery, uri::Scheme, Request, Response, Uri};
use hyper::{
client::{connect::Connection, HttpConnector},
Body,
};
use hyper_util::client::legacy::connect::{Connection, HttpConnector};
use std::{convert::TryInto, fmt::Debug};
use tokio::io::{AsyncRead, AsyncWrite};
use tower_service::Service;

const USER_AGENT_HEADER: &str = "User-Agent";
Expand All @@ -26,7 +22,7 @@ pub struct Client<C = HttpConnector> {
/// The runtime API URI
pub base: Uri,
/// The client that manages the API connections
pub client: hyper::Client<C>,
pub client: hyper_util::client::legacy::Client<C, hyper::body::Incoming>,
}

impl Client {
Expand All @@ -41,19 +37,19 @@ impl Client {

impl<C> Client<C>
where
C: hyper::client::connect::Connect + Sync + Send + Clone + 'static,
C: hyper_util::client::legacy::connect::Connect + Sync + Send + Clone + 'static,
{
/// Send a given request to the Runtime API.
/// Use the client's base URI to ensure the API endpoint is correct.
pub async fn call(&self, req: Request<Body>) -> Result<Response<Body>, Error> {
pub async fn call(&self, req: Request<hyper::body::Incoming>) -> Result<Response<hyper::body::Incoming>, Error> {
let req = self.set_origin(req)?;
let response = self.client.request(req).await?;
Ok(response)
}

/// Create a new client with a given base URI and HTTP connector.
pub fn with(base: Uri, connector: C) -> Self {
let client = hyper::Client::builder()
let client = hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new())
.http1_max_buf_size(1024 * 1024)
.build(connector);
Self { base, client }
Expand Down Expand Up @@ -83,7 +79,7 @@ where
}

/// Builder implementation to construct any Runtime API clients.
pub struct ClientBuilder<C: Service<http::Uri> = hyper::client::HttpConnector> {
pub struct ClientBuilder<C: Service<http::Uri> = HttpConnector> {
connector: C,
uri: Option<http::Uri>,
}
Expand All @@ -93,15 +89,15 @@ where
C: Service<http::Uri> + Clone + Send + Sync + Unpin + 'static,
<C as Service<http::Uri>>::Future: Unpin + Send,
<C as Service<http::Uri>>::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
<C as Service<http::Uri>>::Response: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
<C as Service<http::Uri>>::Response: Connection + Unpin + Send + 'static,
{
/// Create a new builder with a given HTTP connector.
pub fn with_connector<C2>(self, connector: C2) -> ClientBuilder<C2>
where
C2: Service<http::Uri> + Clone + Send + Sync + Unpin + 'static,
<C2 as Service<http::Uri>>::Future: Unpin + Send,
<C2 as Service<http::Uri>>::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
<C2 as Service<http::Uri>>::Response: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
<C2 as Service<http::Uri>>::Response: Connection + Unpin + Send + 'static,
{
ClientBuilder {
connector,
Expand All @@ -116,7 +112,10 @@ where
}

/// Create the new client to interact with the Runtime API.
pub fn build(self) -> Result<Client<C>, Error> {
pub fn build(self) -> Result<Client<C>, Error>
where
C: hyper_util::client::legacy::connect::Connect + Sync + Send + Clone + 'static,
{
let uri = match self.uri {
Some(uri) => uri,
None => {
Expand Down
2 changes: 1 addition & 1 deletion lambda-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ futures = "0.3"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "^1"
bytes = "1.0"
http = "0.2"
http = "1.0"
async-stream = "0.3"
tracing = { version = "0.1.37", features = ["log"] }
tower = { version = "0.4", features = ["util"] }
Expand Down