This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit afd3e121eb05674188e5307f7d7f0b94b9f0efbe Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Nov 8 16:36:41 2023 +0000 Use sendError() rather than working directly with Coyote response The primary benefit is that the standard error page mechanism is invoked. --- .../org/apache/catalina/connector/InputBuffer.java | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/java/org/apache/catalina/connector/InputBuffer.java b/java/org/apache/catalina/connector/InputBuffer.java index 013b4a49a1..db1a052f06 100644 --- a/java/org/apache/catalina/connector/InputBuffer.java +++ b/java/org/apache/catalina/connector/InputBuffer.java @@ -296,7 +296,6 @@ public class InputBuffer extends Reader implements ByteChunk.ByteInputChannel, A * * @throws IOException An underlying IOException occurred */ - @SuppressWarnings("deprecation") @Override public int realReadBytes() throws IOException { if (closed) { @@ -310,21 +309,11 @@ public class InputBuffer extends Reader implements ByteChunk.ByteInputChannel, A try { return coyoteRequest.doRead(this); } catch (BadRequestException bre) { - // Set flag used by asynchronous processing to detect errors on non-container threads - coyoteRequest.setErrorException(bre); - // In synchronous processing, this exception may be swallowed by the application so set error flags here. - coyoteRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, bre); - coyoteRequest.getResponse().setStatus(400); - coyoteRequest.getResponse().setError(); // Make the exception visible to the application + handleReadException(bre); throw bre; } catch (IOException ioe) { - // Set flag used by asynchronous processing to detect errors on non-container threads - coyoteRequest.setErrorException(ioe); - // In synchronous processing, this exception may be swallowed by the application so set error flags here. - coyoteRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe); - coyoteRequest.getResponse().setStatus(400); - coyoteRequest.getResponse().setError(); + handleReadException(ioe); // Any other IOException on a read is almost always due to the remote client aborting the request. // Make the exception visible to the application throw new ClientAbortException(ioe); @@ -332,6 +321,17 @@ public class InputBuffer extends Reader implements ByteChunk.ByteInputChannel, A } + private void handleReadException(Exception e) throws IOException { + // Set flag used by asynchronous processing to detect errors on non-container threads + coyoteRequest.setErrorException(e); + // In synchronous processing, this exception may be swallowed by the application so set error flags here. + Request request = (Request) coyoteRequest.getNote(CoyoteAdapter.ADAPTER_NOTES); + Response response = request.getResponse(); + request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e); + response.sendError(400); + } + + public int readByte() throws IOException { throwIfClosed(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org