Skip to content

Commit

Permalink
Merge pull request #10344 from eclipse/jetty-9.4.x-fixSizeLimitHandler
Browse files Browse the repository at this point in the history
Issue #10337 - fixes to SizeLimitHandler
  • Loading branch information
lachlan-roberts committed Aug 23, 2023
2 parents e4d596e + 325d839 commit eb39055
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import org.eclipse.jetty.server.HttpOutput;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

/**
* <p>A handler that can limit the size of message bodies in requests and responses.</p>
Expand All @@ -46,8 +44,6 @@
*/
public class SizeLimitHandler extends HandlerWrapper
{
private static final Logger LOG = Log.getLogger(SizeLimitHandler.class);

private final long _requestLimit;
private final long _responseLimit;

Expand Down Expand Up @@ -90,7 +86,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
baseRequest.getHttpInput().addInterceptor(limit);
}

if (_responseLimit > 0)
if (_responseLimit >= 0)
{
httpOutput.setInterceptor(limit);
response = new LimitResponse(response);
Expand Down Expand Up @@ -132,7 +128,7 @@ public HttpInput.Content readFrom(HttpInput.Content content)
if (content.hasContent())
{
_read += content.remaining();
checkResponseLimit(_read);
checkRequestLimit(_read);
}
return content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
_local.getResponse("GET /ctx/hello HTTP/1.0\r\n\r\n"));
assertThat(response.getStatus(), equalTo(500));
assertThat(response.getContent(), containsString("8193&gt;8192"));
assertThat(response.getContent(), containsString("Response body is too large"));
}

@Test
Expand All @@ -130,6 +131,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
_local.getResponse("GET /ctx/hello HTTP/1.0\r\n\r\n"));
assertThat(response.getStatus(), equalTo(500));
assertThat(response.getContent(), containsString("8193&gt;8192"));
assertThat(response.getContent(), containsString("Response body is too large"));
}

@Test
Expand Down Expand Up @@ -219,6 +221,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
"\r\n" +
"123456..."));
assertThat(response.getStatus(), equalTo(413));
assertThat(response.getContent(), containsString("Request body is too large"));
assertThat(response.getContent(), containsString("32768&gt;8192"));
}

Expand Down Expand Up @@ -253,7 +256,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques

HttpTester.Response response = HttpTester.parseResponse(endp.getResponse());

assertThat(response.getStatus(), equalTo(500));
assertThat(response.getStatus(), equalTo(413));
assertThat(response.getContent(), containsString("Request body is too large"));
assertThat(response.getContent(), containsString("&gt;8192"));
}
}
Expand Down

0 comments on commit eb39055

Please sign in to comment.