Skip to content

Commit

Permalink
Piss off
Browse files Browse the repository at this point in the history
  • Loading branch information
d-e-s-o committed Feb 12, 2024
1 parent 7336830 commit 0dce82b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ async-trait = "0.1.51"
chrono = {version = "0.4.19", features = ["serde"]}
futures = {version = "0.3", default-features = false}
http = {version = "0.2", default-features = false}
http-body-util = {version = "0.1", default-features = false}
http-endpoint = "0.5"
hyper = {version = "0.14", features = ["client", "http1", "stream"]}
hyper-tls = {version = "0.5", default-features = false}
hyper = {version = "1.1", features = ["client", "http1"]}
hyper-util = {version = "0.1.3", features = ["client-legacy"]}
hyper-tls = {version = "0.6", default-features = false}
num-decimal = {version = "0.2.4", default-features = false, features = ["num-v04", "serde"]}
serde = {version = "1.0.103", features = ["derive"]}
serde_json = {version = "1.0", default-features = false, features = ["std"]}
Expand Down
26 changes: 13 additions & 13 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use http::HeaderMap;
use http::HeaderValue;
use http::Request;
use http::Response;
use http_body_util::combinators::BoxBody;
use http_endpoint::Endpoint;

use hyper::body::Body as _;
use hyper::body::Bytes;
use hyper::body::HttpBody as _;
use hyper::client::Builder as HttpClientBuilder;
use hyper::client::HttpConnector;
use hyper::Body;
use hyper::Client as HttpClient;
use hyper::Error as HyperError;
use hyper_tls::HttpsConnector;
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'h> Debug for DebugHeaders<'h> {
/// A type providing a debug representation of an HTTP request, with
/// sensitive data being masked out.
struct DebugRequest<'r> {
request: &'r Request<Body>,
request: &'r Request<BoxBody>,
}

impl<'r> Debug for DebugRequest<'r> {
Expand All @@ -92,7 +92,7 @@ impl<'r> Debug for DebugRequest<'r> {


/// Emit a debug representation of an HTTP request.
fn debug_request(request: &Request<Body>) -> DebugValue<DebugRequest<'_>> {
fn debug_request(request: &Request<BoxBody>) -> DebugValue<DebugRequest<'_>> {
debug(DebugRequest { request })
}

Expand Down Expand Up @@ -152,7 +152,7 @@ impl Default for Builder {
#[derive(Debug)]
pub struct Client {
api_info: ApiInfo,
client: HttpClient<HttpsConnector<HttpConnector>, Body>,
client: HttpClient<HttpsConnector<HttpConnector>, BoxBody>,
}

impl Client {
Expand All @@ -171,7 +171,7 @@ impl Client {

/// Add "gzip" as an accepted encoding to the request.
#[cfg(feature = "gzip")]
fn maybe_add_gzip_header(request: &mut Request<Body>) {
fn maybe_add_gzip_header(request: &mut Request<BoxBody>) {
use http::header::ACCEPT_ENCODING;

let _ = request
Expand All @@ -181,10 +181,10 @@ impl Client {

/// An implementation stub not actually doing anything.
#[cfg(not(feature = "gzip"))]
fn maybe_add_gzip_header(_request: &mut Request<Body>) {}
fn maybe_add_gzip_header(_request: &mut Request<BoxBody>) {}

/// Create a `Request` to the endpoint.
fn request<R>(&self, input: &R::Input) -> Result<Request<Body>, R::Error>
fn request<R>(&self, input: &R::Input) -> Result<Request<BoxBody>, R::Error>
where
R: Endpoint,
{
Expand All @@ -201,15 +201,15 @@ impl Client {
// Add required authentication information.
.header(HDR_KEY_ID, self.api_info.key_id.as_str())
.header(HDR_SECRET, self.api_info.secret.as_str())
.body(Body::from(
.body(BoxBody::from(
R::body(input)?.unwrap_or(Cow::Borrowed(&[0; 0])),
))?;

Self::maybe_add_gzip_header(&mut request);
Ok(request)
}

async fn retrieve_raw_body(response: Body) -> Result<Bytes, HyperError> {
async fn retrieve_raw_body(response: BoxBody) -> Result<Bytes, HyperError> {
// We unconditionally wait for the full body to be received
// before even evaluating the header. That is mostly done for
// simplicity and it shouldn't really matter anyway because most
Expand All @@ -225,7 +225,7 @@ impl Client {
/// Retrieve the HTTP body, possible uncompressing it if it was gzip
/// encoded.
#[cfg(feature = "gzip")]
async fn retrieve_body<E>(response: Response<Body>) -> Result<Bytes, RequestError<E>> {
async fn retrieve_body<E>(response: Response<BoxBody>) -> Result<Bytes, RequestError<E>> {
use async_compression::futures::bufread::GzipDecoder;
use futures::AsyncReadExt as _;
use http::header::CONTENT_ENCODING;
Expand All @@ -248,7 +248,7 @@ impl Client {

/// Retrieve the HTTP body.
#[cfg(not(feature = "gzip"))]
async fn retrieve_body<E>(response: Response<Body>) -> Result<Bytes, RequestError<E>> {
async fn retrieve_body<E>(response: Response<BoxBody>) -> Result<Bytes, RequestError<E>> {
let bytes = Self::retrieve_raw_body(response.into_body()).await?;
Ok(bytes)
}
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Client {

/// Issue a request.
#[allow(clippy::cognitive_complexity)]
async fn issue_<R>(&self, request: Request<Body>) -> Result<R::Output, RequestError<R::Error>>
async fn issue_<R>(&self, request: Request<BoxBody>) -> Result<R::Output, RequestError<R::Error>>
where
R: Endpoint,
{
Expand Down

0 comments on commit 0dce82b

Please sign in to comment.