Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow BadMessageException to propagate unwrapped through HttpInput #12571

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ private Content intercept(Content content) throws IOException
{
return _interceptor.readFrom(content);
}
catch (RuntimeException | Error x)
{
throw x;
}
catch (Throwable x)
{
IOException failure = new IOException("Bad content", x);
Expand Down Expand Up @@ -1146,6 +1150,8 @@ public int noContent() throws IOException
{
if (_error instanceof IOException)
throw (IOException)_error;
if (_error instanceof RuntimeException)
throw (RuntimeException)_error;
throw new IOException(_error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
String text = new String(data, 0, 1024, Charset.defaultCharset());

for (int i = 0; i < 9; i++)
endp.addInput("400\r\n" + text + "\r\n");
endp.addInput(Integer.toHexString(text.length()) + ";\r\n" + text + "\r\n");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.util.BytesContentProvider;
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpTester;
Expand All @@ -63,9 +64,10 @@
import org.junit.jupiter.params.provider.ValueSource;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -110,10 +112,10 @@ public void handle(String target, Request jettyRequest, HttpServletRequest reque
// Throw immediately from the interceptor.
jettyRequest.getHttpInput().addInterceptor(content ->
{
throw new RuntimeException();
throw new BadMessageException();
});

assertThrows(IOException.class, () -> IO.readBytes(request.getInputStream()));
assertThrows(BadMessageException.class, () -> IO.readBytes(request.getInputStream()));
serverLatch.countDown();
response.setStatus(HttpStatus.NO_CONTENT_204);
}
Expand Down Expand Up @@ -159,7 +161,7 @@ public void handle(String target, Request jettyRequest, HttpServletRequest reque
throw new RuntimeException();
});

assertThrows(IOException.class, () -> IO.readBytes(request.getInputStream()));
assertThrows(RuntimeException.class, () -> IO.readBytes(request.getInputStream()));
serverLatch.countDown();
response.setStatus(HttpStatus.NO_CONTENT_204);
}
Expand Down Expand Up @@ -362,7 +364,7 @@ public void onDataAvailable()
// Now the interceptor should throw, but isReady() should not.
if (input.isReady())
{
assertThrows(IOException.class, () -> assertEquals(bytes[0], input.read()));
assertThrows(RuntimeException.class, () -> assertEquals(bytes[0], input.read()));
readFailureLatch.countDown();
response.setStatus(HttpStatus.NO_CONTENT_204);
asyncContext.complete();
Expand Down Expand Up @@ -431,7 +433,7 @@ public void onAllDataRead()
@Override
public void onError(Throwable error)
{
assertSame(failure, error.getCause());
assertThat(failure, anyOf(sameInstance(error), sameInstance(error.getCause())));
response.setStatus(HttpStatus.NO_CONTENT_204);
asyncContext.complete();
}
Expand Down