Skip to content

Commit

Permalink
Fix ContentSizeLimitFeature when request body is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
amanteaux committed Jan 15, 2025
1 parent ba2664c commit d2adc81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void filter(ContainerRequestContext context) {

public static final class SizeLimitingInputStream extends InputStream {
private long length = 0;
private int mark = 0;
private long mark = 0;

private final int maxSize;

Expand Down Expand Up @@ -129,14 +129,13 @@ public void close() throws IOException {

@Override
public synchronized void mark(final int readlimit) {
mark += readlimit;
mark = length; // Save the current position as the mark
delegateInputStream.mark(readlimit);
}

@Override
public synchronized void reset() throws IOException {
this.length = 0;
readAndCheck(mark);
this.length = mark;
delegateInputStream.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Response uploadDefaultLimit(byte[] data) {

@GET
@Path("/upload-default")
public Response getDefaultLimit(byte[] data) {
public Response getDefaultLimit() {
return Response.ok("get successful").build();
}

Expand All @@ -32,7 +32,7 @@ public Response uploadCustomLimit(byte[] data) {
@GET
@Path("/upload-custom")
@ContentSizeLimit(CUSTOM_MAX_SIZE)
public Response getCustomLimit(byte[] data) {
public Response getCustomLimit() {
return Response.ok("get successful").build();
}

Expand Down

0 comments on commit d2adc81

Please sign in to comment.