From d3b436fb83b0052de559fd87a95c82eda3ce21d4 Mon Sep 17 00:00:00 2001 From: Adwait Kumar Singh Date: Sun, 21 Apr 2024 12:48:32 -0700 Subject: [PATCH] Make status code configurable --- java/org/apache/coyote/http11/Http11Processor.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java index 9f144bb4642b..5c2b7809b433 100644 --- a/java/org/apache/coyote/http11/Http11Processor.java +++ b/java/org/apache/coyote/http11/Http11Processor.java @@ -148,6 +148,11 @@ public class Http11Processor extends AbstractProcessor { */ private SendfileDataBase sendfileData = null; + /** + * Indicates if a bad request was received (if true, the connection will be closed at the end of the request) + */ + private boolean badRequest = false; + public Http11Processor(AbstractHttp11Protocol protocol, Adapter adapter) { super(adapter); @@ -190,7 +195,7 @@ public Http11Processor(AbstractHttp11Protocol protocol, Adapter adapter) { * Determine if we must drop the connection because of the HTTP status code. Use the same list of codes as * Apache/httpd. */ - private static boolean statusDropsConnection(int status) { + protected boolean statusDropsConnection(int status) { return status == 400 /* SC_BAD_REQUEST */ || status == 408 /* SC_REQUEST_TIMEOUT */ || status == 411 /* SC_LENGTH_REQUIRED */ || status == 413 /* SC_REQUEST_ENTITY_TOO_LARGE */ || status == 414 /* SC_REQUEST_URI_TOO_LONG */ || status == 500 /* SC_INTERNAL_SERVER_ERROR */ || @@ -251,6 +256,7 @@ public SocketState service(SocketWrapperBase socketWrapper) throws IOExceptio keepAlive = true; openSocket = false; readComplete = true; + badRequest = false; boolean keptAlive = false; SendfileState sendfileState = SendfileState.DONE; @@ -851,6 +857,7 @@ private void prepareInputFilters(MimeHeaders headers) throws IOException { private void badRequest(String errorKey) { response.setStatus(400); + badRequest = true; setErrorState(ErrorState.CLOSE_CLEAN, null); if (log.isDebugEnabled()) { log.debug(sm.getString(errorKey)); @@ -980,7 +987,7 @@ protected final void prepareResponse() throws IOException { // If we know that the request is bad this early, add the // Connection: close header. - if (keepAlive && statusDropsConnection(statusCode)) { + if (keepAlive && (badRequest || statusDropsConnection(statusCode))) { keepAlive = false; } if (!keepAlive) {