aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_copy.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-05-03 22:45:42 +0200
committerAlex Auvolat <alex@adnab.me>2021-05-06 22:37:15 +0200
commit6ccffc316228bb056fa135cc5fceb2ed75f545f5 (patch)
tree109e9334aaee5b7865a5d29fcfaea23010da0cc4 /src/api/s3_copy.rs
parente4b9e4e24d006373a20cfcbdac9dba5e399ee182 (diff)
downloadgarage-6ccffc316228bb056fa135cc5fceb2ed75f545f5.tar.gz
garage-6ccffc316228bb056fa135cc5fceb2ed75f545f5.zip
Improved XML serializationbetter_xml
- Use quick_xml and serde for all XML response returned by the S3 API. - Include tests for all structs used to generate XML - Remove old manual XML escaping function which was unsafe
Diffstat (limited to 'src/api/s3_copy.rs')
-rw-r--r--src/api/s3_copy.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/api/s3_copy.rs b/src/api/s3_copy.rs
index 7069489b..9ade6985 100644
--- a/src/api/s3_copy.rs
+++ b/src/api/s3_copy.rs
@@ -1,4 +1,3 @@
-use std::fmt::Write;
use std::sync::Arc;
use hyper::{Body, Request, Response};
@@ -14,6 +13,7 @@ use garage_model::version_table::*;
use crate::error::*;
use crate::s3_put::get_headers;
+use crate::s3_xml;
pub async fn handle_copy(
garage: Arc<Garage>,
@@ -61,6 +61,8 @@ pub async fn handle_copy(
_ => old_meta.clone(),
};
+ let etag = new_meta.etag.to_string();
+
// Save object copy
match source_last_state {
ObjectVersionData::DeleteMarker => unreachable!(),
@@ -158,13 +160,13 @@ pub async fn handle_copy(
}
let last_modified = msec_to_rfc3339(new_timestamp);
- let mut xml = String::new();
- writeln!(&mut xml, r#"<?xml version="1.0" encoding="UTF-8"?>"#).unwrap();
- writeln!(&mut xml, r#"<CopyObjectResult>"#).unwrap();
- writeln!(&mut xml, "\t<LastModified>{}</LastModified>", last_modified).unwrap();
- writeln!(&mut xml, "</CopyObjectResult>").unwrap();
+ let result = s3_xml::CopyObjectResult {
+ last_modified: s3_xml::Value(last_modified),
+ etag: s3_xml::Value(etag),
+ };
+ let xml = s3_xml::to_xml_with_header(&result)?;
Ok(Response::builder()
.header("Content-Type", "application/xml")
- .body(Body::from(xml.into_bytes()))?)
+ .body(Body::from(xml))?)
}