mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
Fix crash when request Content-Type header is empty string (#940)
JAX-RS's ContainerRequestContext.getMediaType() parses the Content-Type
header value and throws IllegalArgumentException when the value is an
empty string (as opposed to null/absent). Some S3 clients (e.g.
Paperclip) send 'Content-Type: ""' for uploads without a detected type,
which caused every such request to fail with a 500 error.
Replace ctx.getMediaType() with ctx.getHeaderString("Content-Type") so
the raw value is used for protocol detection without triggering the
JAX-RS media-type parser.
This commit is contained in:
1 parent
60c4edda55
commit
c6928128ff
1 file changed
+3
-1
@@ -76,7 +76,9 @@ public class ServiceEnabledFilter implements ContainerRequestFilter {
|
||||
}
|
||||
|
||||
private java.util.Optional<ServiceProtocol> inferProtocol(ContainerRequestContext ctx) {
|
||||
String contentType = ctx.getMediaType() != null ? ctx.getMediaType().toString() : "";
|
||||
// Use the raw header string to avoid IllegalArgumentException when Content-Type is empty.
|
||||
String contentType = ctx.getHeaderString("Content-Type");
|
||||
if (contentType == null) contentType = "";
|
||||
if (contentType.contains("cbor")) {
|
||||
return java.util.Optional.of(ServiceProtocol.CBOR);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user