diff options
author | Alex Auvolat <alex@adnab.me> | 2021-04-28 01:05:40 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-04-28 01:05:40 +0200 |
commit | dcfc32cf85bc6276fdff2492898c1cbb527e9b9d (patch) | |
tree | 01ec3f7476733dab8c74ecb1c72b5061f6e5c8e1 /src/api/api_server.rs | |
parent | 368eb354846790e9fc616d9a26ddc414748d847f (diff) | |
download | garage-dcfc32cf85bc6276fdff2492898c1cbb527e9b9d.tar.gz garage-dcfc32cf85bc6276fdff2492898c1cbb527e9b9d.zip |
Many S3 compatibility improvements:v0.2.1.5
- return XML errors
- implement AuthorizationHeaderMalformed error to redirect clients to
correct location (used by minio client)
- implement GetBucketLocation
- fix DeleteObjects XML parsing and response
Diffstat (limited to 'src/api/api_server.rs')
-rw-r--r-- | src/api/api_server.rs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/api/api_server.rs b/src/api/api_server.rs index dcc9f478..ab8bd736 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -14,6 +14,7 @@ use garage_model::garage::Garage; use crate::error::*; use crate::signature::check_signature; +use crate::s3_bucket::*; use crate::s3_copy::*; use crate::s3_delete::*; use crate::s3_get::*; @@ -52,17 +53,21 @@ async fn handler( req: Request<Body>, addr: SocketAddr, ) -> Result<Response<Body>, GarageError> { - info!("{} {} {}", addr, req.method(), req.uri()); + let uri = req.uri().clone(); + info!("{} {} {}", addr, req.method(), uri); debug!("{:?}", req); - match handler_inner(garage, req).await { + match handler_inner(garage.clone(), req).await { Ok(x) => { debug!("{} {:?}", x.status(), x.headers()); Ok(x) } Err(e) => { - let body: Body = Body::from(format!("{}\n", e)); - let mut http_error = Response::new(body); - *http_error.status_mut() = e.http_status_code(); + let body: Body = Body::from(e.aws_xml(&garage.config.s3_api.s3_region, uri.path())); + let http_error = Response::builder() + .status(e.http_status_code()) + .header("Content-Type", "application/xml") + .body(body)?; + if e.http_status_code().is_server_error() { warn!("Response: error {}, {}", e.http_status_code(), e); } else { @@ -211,9 +216,14 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon )) } &Method::GET => { - // ListObjects or ListObjectsV2 query - let q = parse_list_objects_query(bucket, ¶ms)?; - Ok(handle_list(garage, &q).await?) + if params.contains_key("location") { + // GetBucketLocation call + Ok(handle_get_bucket_location(garage)?) + } else { + // ListObjects or ListObjectsV2 query + let q = parse_list_objects_query(bucket, ¶ms)?; + Ok(handle_list(garage, &q).await?) + } } &Method::POST => { if params.contains_key(&"delete".to_string()) { |