diff options
Diffstat (limited to 'src/k2v-client')
-rw-r--r-- | src/k2v-client/Cargo.toml | 4 | ||||
-rw-r--r-- | src/k2v-client/error.rs | 2 | ||||
-rw-r--r-- | src/k2v-client/lib.rs | 18 |
3 files changed, 16 insertions, 8 deletions
diff --git a/src/k2v-client/Cargo.toml b/src/k2v-client/Cargo.toml index 9f27c47d..694be1f8 100644 --- a/src/k2v-client/Cargo.toml +++ b/src/k2v-client/Cargo.toml @@ -13,11 +13,13 @@ base64.workspace = true sha2.workspace = true hex.workspace = true http.workspace = true +http-body-util.workspace = true log.workspace = true aws-sigv4.workspace = true aws-sdk-config.workspace = true percent-encoding.workspace = true -hyper = { workspace = true, default-features = false, features = ["client", "http1", "http2"] } +hyper = { workspace = true, default-features = false, features = ["http1", "http2"] } +hyper-util.workspace = true hyper-rustls.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/src/k2v-client/error.rs b/src/k2v-client/error.rs index aa84ee9f..96f5674a 100644 --- a/src/k2v-client/error.rs +++ b/src/k2v-client/error.rs @@ -22,6 +22,8 @@ pub enum Error { Http(#[from] http::Error), #[error("hyper error: {0}")] Hyper(#[from] hyper::Error), + #[error("hyper client error: {0}")] + HyperClient(#[from] hyper_util::client::legacy::Error), #[error("invalid header: {0}")] Header(#[from] hyper::header::ToStrError), #[error("deserialization error: {0}")] diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs index f70442f4..13538909 100644 --- a/src/k2v-client/lib.rs +++ b/src/k2v-client/lib.rs @@ -9,9 +9,11 @@ use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC}; use http::header::{ACCEPT, CONTENT_TYPE}; use http::status::StatusCode; use http::{HeaderName, HeaderValue, Request}; -use hyper::{body::Bytes, body::HttpBody, Body}; -use hyper::{client::connect::HttpConnector, Client as HttpClient}; +use http_body_util::{BodyExt, Full as FullBody}; +use hyper::{body::Body as BodyTrait, body::Bytes}; use hyper_rustls::HttpsConnector; +use hyper_util::client::legacy::{connect::HttpConnector, Client as HttpClient}; +use hyper_util::rt::TokioExecutor; use aws_sdk_config::config::Credentials; use aws_sigv4::http_request::{sign, SignableBody, SignableRequest, SigningSettings}; @@ -24,6 +26,8 @@ mod error; pub use error::Error; +pub type Body = FullBody<Bytes>; + const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5); const DEFAULT_POLL_TIMEOUT: Duration = Duration::from_secs(300); const SERVICE: &str = "k2v"; @@ -55,19 +59,19 @@ pub struct K2vClientConfig { pub struct K2vClient { config: K2vClientConfig, user_agent: HeaderValue, - client: HttpClient<HttpsConnector<HttpConnector>>, + client: HttpClient<HttpsConnector<HttpConnector>, Body>, } impl K2vClient { /// Create a new K2V client. pub fn new(config: K2vClientConfig) -> Result<Self, Error> { let connector = hyper_rustls::HttpsConnectorBuilder::new() - .with_native_roots() + .with_native_roots()? .https_or_http() .enable_http1() .enable_http2() .build(); - let client = HttpClient::builder().build(connector); + let client = HttpClient::builder(TokioExecutor::new()).build(connector); let user_agent: std::borrow::Cow<str> = match &config.user_agent { Some(ua) => ua.into(), None => format!("k2v/{}", env!("CARGO_PKG_VERSION")).into(), @@ -395,7 +399,7 @@ impl K2vClient { // Sign and then apply the signature to the request let (signing_instructions, _signature) = sign(signable_request, &signing_params)?.into_parts(); - signing_instructions.apply_to_request_http0x(&mut req); + signing_instructions.apply_to_request_http1x(&mut req); // Send and wait for timeout let res = tokio::select! { @@ -416,7 +420,7 @@ impl K2vClient { }; let body = match res.status { - StatusCode::OK => body.collect().await?.to_bytes(), + StatusCode::OK => BodyExt::collect(body).await?.to_bytes(), StatusCode::NO_CONTENT => Bytes::new(), StatusCode::NOT_FOUND => return Err(Error::NotFound), StatusCode::NOT_MODIFIED => Bytes::new(), |