Skip to content

Commit

Permalink
Merge pull request #5286 from eclipse/jetty-9.4.x-5285-415-unsupporte…
Browse files Browse the repository at this point in the history
…d-media-type

Issue #5285 - Using Status code 415 Unsupported Media Type instead
  • Loading branch information
joakime authored Sep 17, 2020
2 parents ba22c08 + 290c98e commit c6ed603
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,14 @@ private void extractQueryParameters()
}
}

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();
Expand All @@ -512,12 +520,11 @@ private void extractContentParameters()
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) &&
Expand All @@ -526,8 +533,10 @@ else if (MimeTypes.Type.MULTIPART_FORM_DATA.is(baseType) &&
{
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ public boolean check(HttpServletRequest request, HttpServletResponse response)
}
catch (BadMessageException e)
{
return e.getCode() == 501;
return e.getCode() == 415;
}
}
};
Expand Down

0 comments on commit c6ed603

Please sign in to comment.