Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(s3): remove XML declaration from GetBucketLocation response (#403)

Christine Nguyen3621c32b8824
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
index a33678943c..0f093f0725 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
@@ -1147,17 +1147,17 @@ public class S3Controller {
private Response handleGetBucketLocation(String bucket) {
String region = s3Service.getBucketRegion(bucket);
- XmlBuilder xml = new XmlBuilder()
- .raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ String xml;
if (region == null || "us-east-1".equals(region)) {
- xml.start("LocationConstraint", AwsNamespaces.S3)
- .end("LocationConstraint");
+ xml = "<LocationConstraint xmlns=\"" + AwsNamespaces.S3 + "\"/>";
} else {
- xml.start("LocationConstraint", AwsNamespaces.S3)
+ xml = new XmlBuilder()
+ .start("LocationConstraint", AwsNamespaces.S3)
.raw(XmlBuilder.escape(region))
- .end("LocationConstraint");
+ .end("LocationConstraint")
+ .build();
}
- return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build();
+ return Response.ok(xml).type(MediaType.APPLICATION_XML).build();
}
// --- Bucket Tagging ---
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java
index d1324e6756..4ce1445ed9 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java
@@ -1289,6 +1289,7 @@ class S3IntegrationTest {
.get("/" + bucket + "?location")
.then()
.statusCode(200)
+ .body(not(containsString("<?xml")))
.body(containsString("<LocationConstraint"))
.body(not(containsString("us-east-1")));
@@ -1318,6 +1319,7 @@ class S3IntegrationTest {
.get("/" + bucket + "?location")
.then()
.statusCode(200)
+ .body(not(containsString("<?xml")))
.body(containsString("eu-central-1"));
given().when().delete("/" + bucket);