Skip to content

Commit

Permalink
fix: adjust hyper client usage in llrt_core
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyChan-okta committed Oct 31, 2024
1 parent b201fa0 commit 1ec0582
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions llrt_core/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ use std::{
time::Instant,
};

use bytes::Bytes;
use crate::modules::http::HyperClient;
use chrono::Utc;
use http_body_util::combinators::BoxBody;
use http_body_util::{BodyExt, Full};
use hyper::{
header::{HeaderMap, CONTENT_TYPE},
http::header::HeaderName,
Request, StatusCode,
};
use hyper_rustls::HttpsConnector;
use hyper_util::client::legacy::{connect::HttpConnector, Client};
use llrt_json::{
parse::json_parse,
stringify::{self, json_stringify},
Expand Down Expand Up @@ -119,8 +118,6 @@ pub fn mark_client_inited(rt: *mut qjs::JSRuntime) {
state.latch.decrement();
}

type HyperClient = Client<HttpsConnector<HttpConnector>, Full<Bytes>>;

#[derive(Clone)]
struct LambdaContext<'js, 'a> {
pub aws_request_id: String,
Expand Down Expand Up @@ -292,7 +289,7 @@ async fn next_invocation<'js, 'a>(
.method("GET")
.uri(uri)
.header(CONTENT_TYPE, "application/json")
.body(Full::default())
.body(BoxBody::new(Full::default()))
.or_throw(ctx)?;

let res = client.request(req).await.or_throw(ctx)?;
Expand Down Expand Up @@ -367,9 +364,9 @@ async fn invoke_response<'js>(
.method("POST")
.uri([base_url, "/invocation/", request_id, "/response"].concat())
.header(CONTENT_TYPE, "application/json")
.body(Full::from(bytes::Bytes::from(
.body(BoxBody::new(Full::from(bytes::Bytes::from(
result_json.unwrap_or_default(),
)))
))))
.or_throw(ctx)?;

let res = client.request(req).await.or_throw(ctx)?;
Expand Down Expand Up @@ -541,7 +538,7 @@ async fn post_error<'js>(
.uri(url)
.header(CONTENT_TYPE, "application/json")
.header(&HEADER_ERROR_TYPE, error_type)
.body(Full::from(bytes::Bytes::from(error_body)))
.body(BoxBody::new(Full::from(bytes::Bytes::from(error_body))))
.or_throw(ctx)?;
let res = client.request(req).await.or_throw(ctx)?;
if res.status() != StatusCode::ACCEPTED {
Expand Down
4 changes: 2 additions & 2 deletions modules/llrt_http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ fn get_http_version() -> HttpVersion {
})
}

type HttpsClient = Client<HttpsConnector<HttpConnector>, BoxBody<Bytes, Infallible>>;
pub static HTTP_CLIENT: Lazy<io::Result<HttpsClient>> = Lazy::new(|| {
pub type HyperClient = Client<HttpsConnector<HttpConnector>, BoxBody<Bytes, Infallible>>;
pub static HTTP_CLIENT: Lazy<io::Result<HyperClient>> = Lazy::new(|| {
let pool_idle_timeout = get_pool_idle_timeout();

let maybe_tls_config = match &*TLS_CONFIG {
Expand Down

0 comments on commit 1ec0582

Please sign in to comment.