Dependency upgrades: http, hyper, aws-sdk, smaller deps #703
6 changed files with 13 additions and 13 deletions
|
@ -98,7 +98,7 @@ httpdate = "1.0"
|
||||||
http-range = "0.1"
|
http-range = "0.1"
|
||||||
http-body-util = "0.1"
|
http-body-util = "0.1"
|
||||||
hyper = { version = "1.0", features = ["server", "http1"] }
|
hyper = { version = "1.0", features = ["server", "http1"] }
|
||||||
hyper-util = { verion = "0.1", features = [ "full" ]}
|
hyper-util = { version = "0.1", features = [ "full" ] }
|
||||||
multer = "3.0"
|
multer = "3.0"
|
||||||
percent-encoding = "2.2"
|
percent-encoding = "2.2"
|
||||||
roxmltree = "0.19"
|
roxmltree = "0.19"
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub use garage_model::helper::error::Error as HelperError;
|
||||||
use crate::common_error::CommonError;
|
use crate::common_error::CommonError;
|
||||||
pub use crate::common_error::{CommonErrorDerivative, OkOrBadRequest, OkOrInternalError};
|
pub use crate::common_error::{CommonErrorDerivative, OkOrBadRequest, OkOrInternalError};
|
||||||
use crate::generic_server::ApiError;
|
use crate::generic_server::ApiError;
|
||||||
use crate::helpers::{BytesBody, CustomApiErrorBody};
|
use crate::helpers::*;
|
||||||
|
|
||||||
/// Errors of this crate
|
/// Errors of this crate
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
@ -65,7 +65,7 @@ impl ApiError for Error {
|
||||||
header_map.append(header::CONTENT_TYPE, "application/json".parse().unwrap());
|
header_map.append(header::CONTENT_TYPE, "application/json".parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn http_body(&self, garage_region: &str, path: &str) -> BytesBody {
|
fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody {
|
||||||
let error = CustomApiErrorBody {
|
let error = CustomApiErrorBody {
|
||||||
code: self.code().to_string(),
|
code: self.code().to_string(),
|
||||||
message: format!("{}", self),
|
message: format!("{}", self),
|
||||||
|
@ -81,6 +81,6 @@ impl ApiError for Error {
|
||||||
"#
|
"#
|
||||||
.into()
|
.into()
|
||||||
});
|
});
|
||||||
BytesBody::from(bytes::Bytes::from(error_str.into_bytes()))
|
error_body(error_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ use garage_util::forwarded_headers;
|
||||||
use garage_util::metrics::{gen_trace_id, RecordDuration};
|
use garage_util::metrics::{gen_trace_id, RecordDuration};
|
||||||
use garage_util::socket_address::UnixOrTCPSocketAddress;
|
use garage_util::socket_address::UnixOrTCPSocketAddress;
|
||||||
|
|
||||||
use crate::helpers::{BoxBody, BytesBody};
|
use crate::helpers::{BoxBody, ErrorBody};
|
||||||
|
|
||||||
pub(crate) trait ApiEndpoint: Send + Sync + 'static {
|
pub(crate) trait ApiEndpoint: Send + Sync + 'static {
|
||||||
fn name(&self) -> &'static str;
|
fn name(&self) -> &'static str;
|
||||||
|
@ -40,7 +40,7 @@ pub(crate) trait ApiEndpoint: Send + Sync + 'static {
|
||||||
pub trait ApiError: std::error::Error + Send + Sync + 'static {
|
pub trait ApiError: std::error::Error + Send + Sync + 'static {
|
||||||
fn http_status_code(&self) -> StatusCode;
|
fn http_status_code(&self) -> StatusCode;
|
||||||
fn add_http_headers(&self, header_map: &mut HeaderMap<HeaderValue>);
|
fn add_http_headers(&self, header_map: &mut HeaderMap<HeaderValue>);
|
||||||
fn http_body(&self, garage_region: &str, path: &str) -> BytesBody;
|
fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub fn key_after_prefix(pfx: &str) -> Option<String> {
|
||||||
// =============== body helpers =================
|
// =============== body helpers =================
|
||||||
|
|
||||||
pub type EmptyBody = http_body_util::Empty<bytes::Bytes>;
|
pub type EmptyBody = http_body_util::Empty<bytes::Bytes>;
|
||||||
pub type BytesBody = FullBody<bytes::Bytes>;
|
pub type ErrorBody = FullBody<bytes::Bytes>;
|
||||||
pub type BoxBody<E> = http_body_util::combinators::BoxBody<bytes::Bytes, E>;
|
pub type BoxBody<E> = http_body_util::combinators::BoxBody<bytes::Bytes, E>;
|
||||||
|
|
||||||
pub fn string_body<E>(s: String) -> BoxBody<E> {
|
pub fn string_body<E>(s: String) -> BoxBody<E> {
|
||||||
|
@ -156,8 +156,8 @@ pub fn bytes_body<E>(b: bytes::Bytes) -> BoxBody<E> {
|
||||||
pub fn empty_body<E>() -> BoxBody<E> {
|
pub fn empty_body<E>() -> BoxBody<E> {
|
||||||
BoxBody::new(http_body_util::Empty::new().map_err(|_| unreachable!()))
|
BoxBody::new(http_body_util::Empty::new().map_err(|_| unreachable!()))
|
||||||
}
|
}
|
||||||
pub fn string_bytes_body(s: String) -> BytesBody {
|
pub fn error_body(s: String) -> ErrorBody {
|
||||||
BytesBody::from(bytes::Bytes::from(s.into_bytes()))
|
ErrorBody::from(bytes::Bytes::from(s.into_bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn parse_json_body<T, B, E>(req: Request<B>) -> Result<T, E>
|
pub async fn parse_json_body<T, B, E>(req: Request<B>) -> Result<T, E>
|
||||||
|
|
|
@ -94,7 +94,7 @@ impl ApiError for Error {
|
||||||
header_map.append(header::CONTENT_TYPE, "application/json".parse().unwrap());
|
header_map.append(header::CONTENT_TYPE, "application/json".parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn http_body(&self, garage_region: &str, path: &str) -> BytesBody {
|
fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody {
|
||||||
let error = CustomApiErrorBody {
|
let error = CustomApiErrorBody {
|
||||||
code: self.code().to_string(),
|
code: self.code().to_string(),
|
||||||
message: format!("{}", self),
|
message: format!("{}", self),
|
||||||
|
@ -110,6 +110,6 @@ impl ApiError for Error {
|
||||||
"#
|
"#
|
||||||
.into()
|
.into()
|
||||||
});
|
});
|
||||||
string_bytes_body(error_str)
|
error_body(error_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ impl ApiError for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn http_body(&self, garage_region: &str, path: &str) -> BytesBody {
|
fn http_body(&self, garage_region: &str, path: &str) -> ErrorBody {
|
||||||
let error = s3_xml::Error {
|
let error = s3_xml::Error {
|
||||||
code: s3_xml::Value(self.aws_code().to_string()),
|
code: s3_xml::Value(self.aws_code().to_string()),
|
||||||
message: s3_xml::Value(format!("{}", self)),
|
message: s3_xml::Value(format!("{}", self)),
|
||||||
|
@ -185,6 +185,6 @@ impl ApiError for Error {
|
||||||
"#
|
"#
|
||||||
.into()
|
.into()
|
||||||
});
|
});
|
||||||
string_bytes_body(error_str)
|
error_body(error_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue