aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_list.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-05-01 14:30:50 +0000
committerAlex Auvolat <alex@adnab.me>2020-05-01 14:30:50 +0000
commit33249717010b1173fc28ba188e5fe6d580fbf393 (patch)
treeeb9253a961584ac164fdaae60ba3b84b8e7ae4ab /src/api/s3_list.rs
parent3686f100b7e46d60758e4a1cc70586444ddb5f7a (diff)
downloadgarage-33249717010b1173fc28ba188e5fe6d580fbf393.tar.gz
garage-33249717010b1173fc28ba188e5fe6d580fbf393.zip
Slightly improved S3 compatibility
- ListBucket does not require any of the parameters (delimiter, prefix, max-keys, etc) - URLs are properly percent_decoded - PutObject and DeleteObject calls now answer correctly (empty body, version id in the x-amz-version-id: header)
Diffstat (limited to 'src/api/s3_list.rs')
-rw-r--r--src/api/s3_list.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/api/s3_list.rs b/src/api/s3_list.rs
index ffde609f..df792da2 100644
--- a/src/api/s3_list.rs
+++ b/src/api/s3_list.rs
@@ -29,6 +29,7 @@ pub async fn handle_list(
) -> Result<Response<BodyType>, Error> {
let mut result_keys = BTreeMap::<String, ListResultInfo>::new();
let mut result_common_prefixes = BTreeSet::<String>::new();
+
let mut truncated = true;
let mut next_chunk_start = marker.unwrap_or(prefix).to_string();
@@ -44,12 +45,19 @@ pub async fn handle_list(
max_keys,
)
.await?;
+ debug!(
+ "List: get range {} (max {}), results: {}",
+ next_chunk_start,
+ max_keys,
+ objects.len()
+ );
+
for object in objects.iter() {
+ if !object.key.starts_with(prefix) {
+ truncated = false;
+ break;
+ }
if let Some(version) = object.versions().iter().find(|x| x.is_data()) {
- if !object.key.starts_with(prefix) {
- truncated = false;
- break;
- }
let common_prefix = if delimiter.len() > 0 {
let relative_key = &object.key[prefix.len()..];
match relative_key.find(delimiter) {
@@ -117,7 +125,7 @@ pub async fn handle_list(
for pfx in result_common_prefixes.iter() {
writeln!(
&mut xml,
- "\t<Prefix>{}</Prefix>",
+ "\t\t<Prefix>{}</Prefix>",
xml_escape(pfx),
//xml_encode_key(pfx, urlencode_resp)
)
@@ -126,6 +134,7 @@ pub async fn handle_list(
writeln!(&mut xml, "\t</CommonPrefixes>").unwrap();
}
writeln!(&mut xml, "</ListBucketResult>").unwrap();
+ println!("{}", xml);
Ok(Response::new(Box::new(BytesBody::from(xml.into_bytes()))))
}