Skip to content

Hyper 1 upgrade #749

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

Merged
merged 18 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: update hyper with legacy
  • Loading branch information
simbleau authored and calavera committed Dec 9, 2023
commit b15b95436994bb1e68653e5e41fc8f05274e40ea
8 changes: 1 addition & 7 deletions lambda-extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ async-stream = "0.3"
bytes = "1.0"
chrono = { version = "0.4", features = ["serde"] }
http = "1.0"
hyper = { version = "0.14.20", features = [
"http1",
"client",
"server",
"stream",
"runtime",
] }
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"
Expand Down
8 changes: 8 additions & 0 deletions lambda-runtime-api-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ readme = "README.md"

[dependencies]
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