|
|
@ -43,6 +43,8 @@ use std::fmt::Debug;
|
|
|
|
|
|
|
|
|
|
|
|
const ACCESS_KEY_HEADER: &str = "Hydrus-Client-API-Access-Key";
|
|
|
|
const ACCESS_KEY_HEADER: &str = "Hydrus-Client-API-Access-Key";
|
|
|
|
const CONTENT_TYPE_HEADER: &str = "Content-Type";
|
|
|
|
const CONTENT_TYPE_HEADER: &str = "Content-Type";
|
|
|
|
|
|
|
|
const ACCEPT_HEADER: &str = "Accept";
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "cbor")]
|
|
|
|
#[cfg(feature = "cbor")]
|
|
|
|
const CONTENT_TYPE_CBOR: &str = "application/cbor";
|
|
|
|
const CONTENT_TYPE_CBOR: &str = "application/cbor";
|
|
|
|
#[cfg(feature = "json")]
|
|
|
|
#[cfg(feature = "json")]
|
|
|
@ -455,6 +457,7 @@ impl Client {
|
|
|
|
.get(format!("{}/{}", self.base_url, E::path()))
|
|
|
|
.get(format!("{}/{}", self.base_url, E::path()))
|
|
|
|
.header(ACCESS_KEY_HEADER, &self.access_key)
|
|
|
|
.header(ACCESS_KEY_HEADER, &self.access_key)
|
|
|
|
.header(CONTENT_TYPE_HEADER, content_type)
|
|
|
|
.header(CONTENT_TYPE_HEADER, content_type)
|
|
|
|
|
|
|
|
.header(ACCEPT_HEADER, content_type)
|
|
|
|
.query(query)
|
|
|
|
.query(query)
|
|
|
|
.query(¶ms)
|
|
|
|
.query(¶ms)
|
|
|
|
.send()
|
|
|
|
.send()
|
|
|
@ -509,7 +512,8 @@ impl Client {
|
|
|
|
.post(format!("{}/{}", self.base_url, E::path()))
|
|
|
|
.post(format!("{}/{}", self.base_url, E::path()))
|
|
|
|
.body(body)
|
|
|
|
.body(body)
|
|
|
|
.header(ACCESS_KEY_HEADER, &self.access_key)
|
|
|
|
.header(ACCESS_KEY_HEADER, &self.access_key)
|
|
|
|
.header("Content-Type", content_type)
|
|
|
|
.header(CONTENT_TYPE_HEADER, content_type)
|
|
|
|
|
|
|
|
.header(ACCEPT_HEADER, content_type)
|
|
|
|
.send()
|
|
|
|
.send()
|
|
|
|
.await?;
|
|
|
|
.await?;
|
|
|
|
let response = Self::extract_error(response).await?;
|
|
|
|
let response = Self::extract_error(response).await?;
|
|
|
@ -551,17 +555,24 @@ impl Client {
|
|
|
|
#[tracing::instrument(skip(self, data), level = "trace")]
|
|
|
|
#[tracing::instrument(skip(self, data), level = "trace")]
|
|
|
|
async fn post_binary<E: Endpoint>(&self, data: Vec<u8>) -> Result<E::Response> {
|
|
|
|
async fn post_binary<E: Endpoint>(&self, data: Vec<u8>) -> Result<E::Response> {
|
|
|
|
tracing::trace!("Binary POST request to {}", E::path());
|
|
|
|
tracing::trace!("Binary POST request to {}", E::path());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "cbor")]
|
|
|
|
|
|
|
|
let content_type = CONTENT_TYPE_CBOR;
|
|
|
|
|
|
|
|
#[cfg(feature = "json")]
|
|
|
|
|
|
|
|
let content_type = CONTENT_TYPE_JSON;
|
|
|
|
|
|
|
|
|
|
|
|
let response = self
|
|
|
|
let response = self
|
|
|
|
.inner
|
|
|
|
.inner
|
|
|
|
.post(format!("{}/{}", self.base_url, E::path()))
|
|
|
|
.post(format!("{}/{}", self.base_url, E::path()))
|
|
|
|
.body(data)
|
|
|
|
.body(data)
|
|
|
|
.header(ACCESS_KEY_HEADER, &self.access_key)
|
|
|
|
.header(ACCESS_KEY_HEADER, &self.access_key)
|
|
|
|
.header(CONTENT_TYPE_HEADER, "application/octet-stream")
|
|
|
|
.header(CONTENT_TYPE_HEADER, "application/octet-stream")
|
|
|
|
|
|
|
|
.header(ACCEPT_HEADER, content_type)
|
|
|
|
.send()
|
|
|
|
.send()
|
|
|
|
.await?;
|
|
|
|
.await?;
|
|
|
|
let response = Self::extract_error(response).await?;
|
|
|
|
let response = Self::extract_error(response).await?;
|
|
|
|
|
|
|
|
|
|
|
|
response.json::<E::Response>().await.map_err(Error::from)
|
|
|
|
Self::extract_content(response).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns an error with the response text content if the status doesn't indicate success
|
|
|
|
/// Returns an error with the response text content if the status doesn't indicate success
|
|
|
|