billbarker 2003/07/05 23:23:40 Modified: http11/src/java/org/apache/coyote/http11 Tag: coyote_10 Http11Processor.java Log: Port Patch for closing connections on bad requests. Revision Changes Path No revision No revision 1.55.2.2 +26 -0 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java Index: Http11Processor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v retrieving revision 1.55.2.1 retrieving revision 1.55.2.2 diff -u -r1.55.2.1 -r1.55.2.2 --- Http11Processor.java 13 May 2003 22:47:00 -0000 1.55.2.1 +++ Http11Processor.java 6 Jul 2003 06:23:40 -0000 1.55.2.2 @@ -599,6 +599,15 @@ if (!error) { try { adapter.service(request, response); + // Handle when the response was committed before a serious + // error occurred. Throwing a ServletException should both + // set the status to 500 and set the errorException. + // If we fail here, then the response is likely already + // committed, so we can't try and set headers. + if(keepAlive && !error) { // Avoid checking twice. + error = response.getErrorException() != null || + statusDropsConnection(response.getStatus()); + } } catch (InterruptedIOException e) { error = true; } catch (Throwable t) { @@ -1204,6 +1213,9 @@ keepAlive = false; } + // If we know that the request is bad this early, add the + // Connection: close header. + keepAlive = keepAlive && statusDropsConnection(statusCode); if (!keepAlive) { response.addHeader("Connection", "close"); } else if (!http11) { @@ -1302,5 +1314,19 @@ } + /** + * Determine if we must drop the connection because of the HTTP status + * code. Use the same list of codes as Apache/httpd. + */ + 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_LARGE */ || + status == 500 /* SC_INTERNAL_SERVER_ERROR */ || + status == 503 /* SC_SERVICE_UNAVAILABLE */ || + status == 501 /* SC_NOT_IMPLEMENTED */; + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]