Skip to content
Open
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
5 changes: 0 additions & 5 deletions src/blocking.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait Client {
fn execute(&self, req: Request<Vec<u8>>) -> Result<Response<Vec<u8>>, ClientError> {
debug!(
"Client sending {} request to {} with {} bytes of data",
req.method().to_string(),
req.method(),
req.uri(),
req.body().len(),
);
Expand Down
4 changes: 0 additions & 4 deletions src/blocking/clients.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/blocking/clients/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl RustifyClient for Client {
response
.bytes()
.map_err(|e| ClientError::ResponseError { source: e.into() })?
.to_vec(),
.into(),
)
.map_err(|e| ClientError::ResponseError { source: e.into() })
}
Expand Down
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait Client: Sync + Send {
async fn execute(&self, req: Request<Vec<u8>>) -> Result<Response<Vec<u8>>, ClientError> {
debug!(
"Client sending {} request to {} with {} bytes of data",
req.method().to_string(),
req.method(),
req.uri(),
req.body().len(),
);
Expand All @@ -44,7 +44,7 @@ pub trait Client: Sync + Send {
if !HTTP_SUCCESS_CODES.contains(&response.status().as_u16()) {
return Err(ClientError::ServerResponseError {
code: response.status().as_u16(),
content: String::from_utf8(response.body().to_vec()).ok(),
content: String::from_utf8(response.into_body()).ok(),
});
}

Expand Down
4 changes: 0 additions & 4 deletions src/clients.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/clients/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl RustifyClient for Client {
.bytes()
.await
.map_err(|e| ClientError::ResponseError { source: e.into() })?
.to_vec(),
.into(),
)
.map_err(|e| ClientError::ResponseError { source: e.into() })
}
Expand Down
6 changes: 3 additions & 3 deletions src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Contains common enums used across the crate

/// Represents a HTTP request method
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub enum RequestMethod {
CONNECT,
DELETE,
Expand Down Expand Up @@ -34,13 +34,13 @@ impl Into<http::Method> for RequestMethod {
}

/// Represents the type of a HTTP request body
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub enum RequestType {
JSON,
}

/// Represents the type of a HTTP response body
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub enum ResponseType {
JSON,
}
8 changes: 3 additions & 5 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ pub fn build_body(object: &impl Serialize, ty: RequestType) -> Result<Vec<u8>, C
let parse_data = serde_json::to_string(object)
.map_err(|e| ClientError::DataParseError { source: e.into() })?;
Ok(match parse_data.as_str() {
"null" => "".as_bytes().to_vec(),
"{}" => "".as_bytes().to_vec(),
_ => parse_data.as_bytes().to_vec(),
"null" | "{}" => Vec::new(),
_ => parse_data.into(),
})
}
}
Expand All @@ -44,15 +43,14 @@ pub fn build_request(
debug!("Building endpoint request");
let uri = build_url(base, path, query)?;

let method_err = method.clone();
let uri_err = uri.to_string();
Request::builder()
.uri(uri)
.method(method)
.body(data.unwrap_or_default())
.map_err(|e| ClientError::RequestBuildError {
source: e,
method: method_err,
method,
url: uri_err,
})
}
Expand Down
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,34 @@
extern crate tracing;

#[cfg(feature = "blocking")]
pub mod blocking;
pub mod blocking {
//! Contains blocking variants of clients for executing
//! [Endpoints][crate::endpoint::Endpoint]

pub mod client;
pub mod clients {
//! Contains implementations of [Client][crate::blocking::client::Client] which
//! use varying blocking HTTP clients.
#[cfg(feature = "reqwest")]
pub mod reqwest;
}
}
pub mod client;
pub mod clients;
pub mod clients {
//! Contains implementations of [Client][crate::client::Client] which use
//! varying HTTP clients.
#[cfg(feature = "reqwest")]
pub mod reqwest;
}
pub mod endpoint;
pub mod enums;
pub mod errors;
pub mod http;

#[doc(hidden)]
#[path = "private/mod.rs"]
pub mod __private;
pub mod __private {
pub use serde;
}

pub use crate::{
clients::reqwest::Client,
Expand Down
1 change: 0 additions & 1 deletion src/private/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl MiddleWare for Middle {
content: String::from_utf8(resp_body.to_vec()).ok(),
})?;
let data = wrapper.result.to_string();
*resp.body_mut() = data.as_bytes().to_vec();
*resp.body_mut() = data.into();
Ok(())
}
}