Skip to content

Commit

Permalink
Refacto ContentControlFeature pour ne pas générer une exception à cha…
Browse files Browse the repository at this point in the history
…que GET
  • Loading branch information
bvasseur-urw committed Sep 23, 2024
1 parent 295ce44 commit 0c05d1d
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ public ContentSizeLimitInterceptor(int maxSize) {
// https://stackoverflow.com/questions/24516444/best-way-to-make-jersey-2-x-refuse-requests-with-incorrect-content-length
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
Integer headerContentLength;
try {
headerContentLength = Integer.parseInt(context.getHeaders().getFirst(HttpHeaders.CONTENT_LENGTH));
} catch (NumberFormatException e) {
headerContentLength = maxSize; // default value for GET or chunked body
int headerContentLength = maxSize; // default value for GET or chunked body
String contentLengthHeader = context.getHeaders().getFirst(HttpHeaders.CONTENT_LENGTH);
if (contentLengthHeader != null) {
try {
headerContentLength = Integer.parseInt(contentLengthHeader);
} catch (NumberFormatException e) {
logger.warn("Wrong content length header received: {}", contentLengthHeader);
}
}

if (headerContentLength > maxSize) {
throw new WebApplicationException(
Response.status(Response.Status.REQUEST_ENTITY_TOO_LARGE)
Expand Down

0 comments on commit 0c05d1d

Please sign in to comment.