fix(s3): strip charset parameter from XML response Content-Type (#809)

* fix(s3): strip charset parameter from XML response Content-Type

Real AWS S3 returns `Content-Type: application/xml` for every XML
response, but Quarkus REST automatically appends `;charset=UTF-8` to
text-like media types declared via `@Produces(APPLICATION_XML)`. Some
SDKs treat the extra parameter as a wire-format deviation.

A `ContainerRequestFilter` registers a Vert.x `addHeadersEndHandler`
that strips the charset just before HTTP headers hit the wire. The
hook is necessary because for `Response.ok(entity).build()` (the
common pattern in S3Controller), Quarkus REST's optimised write path
bypasses both `ContainerResponseFilter` and `WriterInterceptor` — they
see `getMediaType() == null`.

Test: S3ContentTypeCharsetFilterTest covers ListBuckets (200) and
NoSuchBucket (404).

* fix(s3): address review feedback on charset filter

- Trim class-level Javadoc to match sibling-filter convention.
- Add @ApplicationScoped so the filter is a single shared CDI bean,
  matching the S3VirtualHostFilter pattern.
- Tighten the semicolon-index guard from semi <= 0 to semi < 0 (a
  semicolon at index 0 is not a valid MediaType).
- Add jsonResponseContentTypeUntouched regression test against
  /_floci/health to guard against future widening of the XML guard.
This commit is contained in:
RyotaroKoshio authored and GitHub committed 2026-05-14 07:11:33 -05:00
1 parent 3bf16e3fb9
commit 6f57af3edc
2 files changed
+84

No files matched your search

@@ -0,0 +1,46 @@
package io.github.hectorvent.floci.services.s3;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
/**
* Verifies S3 XML responses match the real AWS wire format
* ({@code Content-Type: application/xml}, no {@code charset} parameter).
*/
@QuarkusTest
class S3ContentTypeCharsetFilterTest {
@Test
void listBucketsContentTypeHasNoCharset() {
given()
.when()
.get("/")
.then()
.statusCode(200)
.header("Content-Type", equalTo("application/xml"));
}
@Test
void noSuchBucketErrorContentTypeHasNoCharset() {
given()
.when()
.get("/charset-test-missing-bucket-xyz")
.then()
.statusCode(404)
.header("Content-Type", equalTo("application/xml"));
}
@Test
void jsonResponseContentTypeUntouched() {
given()
.when()
.get("/_floci/health")
.then()
.statusCode(200)
.header("Content-Type", startsWith("application/json"));
}
}