WebsiteConfiguration: do not emit empty XML attributes for absent values (#1391)

This fixes a regression wrt garage-v1, likely caused by the version upgrade of quick_xml.

Currently, garage-v2 will emit empty ErrorDocument/IndexDocument/RedirectAllRequestsTo attributes in the response of GetBucketWebsite if there are no corresponding values.
This is somewhat wrong; at least, the S3 documentation for RedirectAllRequestsTo (https://docs.aws.amazon.com/AmazonS3/latest/API/API_RedirectAllRequestsTo.html) writes that it has a required HostName field. So emitting an empty RedirectAllRequestsTo is invalid.

This PR skips emitting XML attributes for these parameters if they contain no value.

Co-authored-by: Armaël Guéneau <armael.gueneau@ens-lyon.org>
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1391
Co-authored-by: Armael <armael@noreply.localhost>
Co-committed-by: Armael <armael@noreply.localhost>
This commit is contained in:
Armael
2026-04-13 13:59:32 +00:00
committed by Alex
parent f9605fae78
commit 6fd9bba0cb
+23 -3
View File
@@ -10,11 +10,14 @@ use crate::xml::{xmlns_tag, IntValue, Value};
pub struct WebsiteConfiguration {
#[serde(rename = "@xmlns", serialize_with = "xmlns_tag", skip_deserializing)]
pub xmlns: (),
#[serde(rename = "ErrorDocument")]
#[serde(rename = "ErrorDocument", skip_serializing_if = "Option::is_none")]
pub error_document: Option<Key>,
#[serde(rename = "IndexDocument")]
#[serde(rename = "IndexDocument", skip_serializing_if = "Option::is_none")]
pub index_document: Option<Suffix>,
#[serde(rename = "RedirectAllRequestsTo")]
#[serde(
rename = "RedirectAllRequestsTo",
skip_serializing_if = "Option::is_none"
)]
pub redirect_all_requests_to: Option<Target>,
#[serde(
rename = "RoutingRules",
@@ -400,4 +403,21 @@ mod tests {
assert_eq!(unprettify_xml(message), unprettify_xml(&message2));
}
#[test]
fn test_serialize_empty() {
let conf = WebsiteConfiguration {
xmlns: (),
error_document: None,
index_document: None,
redirect_all_requests_to: None,
routing_rules: RoutingRules { rules: vec![] },
};
let serialized_ref = r#"<?xml version="1.0" encoding="UTF-8"?>
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
</WebsiteConfiguration>"#;
let serialized = to_xml_with_header(&conf).expect("xml serialization");
assert_eq!(unprettify_xml(&serialized), unprettify_xml(&serialized_ref));
}
}