diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 9417e5c37a3..5ca2bc8b933 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -497,6 +497,14 @@ public class Request implements HttpServletRequest } } + private boolean isContentEncodingSupported() + { + String contentEncoding = getHttpFields().get(HttpHeader.CONTENT_ENCODING); + if (contentEncoding == null) + return true; + return HttpHeaderValue.IDENTITY.is(contentEncoding); + } + private void extractContentParameters() { String contentType = getContentType(); @@ -512,12 +520,11 @@ public class Request implements HttpServletRequest if (MimeTypes.Type.FORM_ENCODED.is(baseType) && _channel.getHttpConfiguration().isFormEncodedMethod(getMethod())) { - if (_metaData != null) + if (_metaData != null && !isContentEncodingSupported()) { - String contentEncoding = getHttpFields().get(HttpHeader.CONTENT_ENCODING); - if (contentEncoding != null && !HttpHeaderValue.IDENTITY.is(contentEncoding)) - throw new BadMessageException(HttpStatus.NOT_IMPLEMENTED_501, "Unsupported Content-Encoding"); + throw new BadMessageException(HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, "Unsupported Content-Encoding"); } + extractFormParameters(_contentParameters); } else if (MimeTypes.Type.MULTIPART_FORM_DATA.is(baseType) && @@ -526,8 +533,10 @@ public class Request implements HttpServletRequest { try { - if (_metaData != null && getHttpFields().contains(HttpHeader.CONTENT_ENCODING)) - throw new BadMessageException(HttpStatus.NOT_IMPLEMENTED_501, "Unsupported Content-Encoding"); + if (_metaData != null && !isContentEncodingSupported()) + { + throw new BadMessageException(HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, "Unsupported Content-Encoding"); + } getParts(_contentParameters); } catch (IOException e) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index d015ae8ece9..4227ad685e4 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -613,7 +613,7 @@ public class RequestTest } catch (BadMessageException e) { - return e.getCode() == 501; + return e.getCode() == 415; } } };