mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
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:
1 parent
3bf16e3fb9
commit
6f57af3edc
2 files changed
+84
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.vertx.http.runtime.CurrentVertxRequest;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
|
||||
/**
|
||||
* Strips the {@code charset} parameter from {@code application/xml} and
|
||||
* {@code text/xml} response Content-Type headers so they match the real AWS
|
||||
* XML protocol wire format.
|
||||
*/
|
||||
@Provider
|
||||
@ApplicationScoped
|
||||
public class S3ContentTypeCharsetFilter implements ContainerRequestFilter {
|
||||
|
||||
@Inject
|
||||
CurrentVertxRequest currentVertxRequest;
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext) {
|
||||
RoutingContext rc = currentVertxRequest.getCurrent();
|
||||
if (rc == null) return;
|
||||
rc.addHeadersEndHandler(v -> {
|
||||
String ct = rc.response().headers().get("Content-Type");
|
||||
if (ct == null) return;
|
||||
int semi = ct.indexOf(';');
|
||||
if (semi < 0) return;
|
||||
String base = ct.substring(0, semi).trim();
|
||||
if ("application/xml".equalsIgnoreCase(base) || "text/xml".equalsIgnoreCase(base)) {
|
||||
rc.response().headers().set("Content-Type", base);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user