add proper request router for s3 api #163

Merged
lx merged 5 commits from trinity-1686a/garage:s3-router into main 2021-12-06 14:17:47 +00:00
Showing only changes of commit bb2e74d98c - Show all commits

View file

@ -38,7 +38,7 @@ macro_rules! s3_match {
)*)? )*)?
}), }),
)* )*
_ => Err(Error::BadRequest("Invalid endpoint".to_owned())), (kw, _) => Err(Error::BadRequest(format!("Invalid endpoint: {}", kw)))
} }
}}; }};
@ -443,13 +443,17 @@ impl Endpoint {
} }
let (bucket, key) = if let Some(bucket) = bucket { let (bucket, key) = if let Some(bucket) = bucket {
(bucket, path.to_owned()) (bucket, path)
} else { } else {
path.split_once('/') path.split_once('/')
.map(|(b, p)| (b.to_owned(), p.trim_start_matches('/').to_owned())) .map(|(b, p)| (b.to_owned(), p.trim_start_matches('/')))
.unwrap_or((path.to_owned(), String::new())) .unwrap_or((path.to_owned(), ""))
}; };
let key = percent_encoding::percent_decode_str(key)
.decode_utf8()?
.into_owned();
let mut query = QueryParameters::from_query(query.unwrap_or_default())?; let mut query = QueryParameters::from_query(query.unwrap_or_default())?;
let res = match *req.method() { let res = match *req.method() {
@ -863,10 +867,14 @@ macro_rules! generateQueryParameters {
for (k, v) in url::form_urlencoded::parse(query.as_bytes()) { for (k, v) in url::form_urlencoded::parse(query.as_bytes()) {
let repeated = match k.as_ref() { let repeated = match k.as_ref() {
$( $(
$rest => res.$name.replace(v).is_some(), $rest => if !v.is_empty() {
res.$name.replace(v).is_some()
} else {
false
},
)* )*
_ => { _ => {
if k.starts_with("response-") { if k.starts_with("response-") || k.starts_with("X-Amz-") {
false false
} else if v.as_ref().is_empty() { } else if v.as_ref().is_empty() {
if res.keyword.replace(k).is_some() { if res.keyword.replace(k).is_some() {