Bug 32292 - HTTP response 505 and Keep-Alive processing
Summary: HTTP response 505 and Keep-Alive processing
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 4
Classification: Unclassified
Component: Connector:Coyote HTTP/1.1 (show other bugs)
Version: 4.1.30
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
: 32293 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-11-18 13:33 UTC by Naru Hayashi
Modified: 2004-12-14 23:17 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Naru Hayashi 2004-11-18 13:33:49 UTC
The following operation was found although it was not so big a problem.
Then telneted to port 8080(tomcat 4.1.30) and gave following request
 (bat request because 2 spaspace befor "HTTP/1.1").
----
HEAD /index.html  HTTP/1.0


----
response was following
----
HTTP/1.1 505 HTTP Version Not Supported
Date: Thu, 18 Nov 2004 07:34:18 GMT
Server: Apache-Coyote/1.1
Connection: Keep-Alive
----
Although a response header means KEEP-ALIVE processing,
socket close immediately.

I think that correction would be inadequate at 4.1.27 folowing code.
org.apache.coyote.http11.Http11Processor#statusDropsConnection
----
    /**
     * 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 */;
    }
----
I think that 505 should also be included here, but it does not know 
whether be else or not.(...or other fix code)

regards,
Naru Hayashi from Japan
Comment 1 Mark Thomas 2004-11-18 23:49:44 UTC
*** Bug 32293 has been marked as a duplicate of this bug. ***
Comment 2 Mark Thomas 2004-11-19 20:04:27 UTC
I disagree.

Imagine that Tomcat only supported HTTP/1.0

The UA makes a request using HTTP/1.1, receieves the 505 and therefore elects 
to repeat the request but using HTTP/1.0. In this case it makes sense to keep 
the connection open.
Comment 3 Naru Hayashi 2004-12-08 09:21:05 UTC
Thank you for your reply.
I can understand that the response 505 and the connection should
 be Keep-Alive are not wrong in this matter. but the problem is 
altough the response said "Connection: Keep-Alive" the real 
connection is closed after the response.

In regarding to this matter I think there are 2 problems.
1. Regarding to "HEAD /index.html  HTTP/1.0" response I think it
 is better to response with 400 rather than 505 (there are 2 
spaces after URI so I think it is a Bad Request)
2. Regarding to "HEAD /index.html HTTP/1.2" response I think it 
is better to response with 505 but the Socket should not be 
closed immediately

So I think to try to solve the problems with
1) for number 1 solution
org.apache.coyote.http11.Http11Processor#prepareRequest()
(line No.1090)
-----------------
    protected void prepareRequest() {

        http11 = true;
        http09 = false;
        contentDelimitation = false;
        expectation = false;
        if (sslSupport != null) {
            request.scheme().setString("https");
        }
        MessageBytes protocolMB = request.protocol();
        if (protocolMB.equals(Constants.HTTP_11)) {
            http11 = true;
            protocolMB.setString(Constants.HTTP_11);
        } else if (protocolMB.equals(Constants.HTTP_10)) {
            http11 = false;
            keepAlive = false;
            protocolMB.setString(Constants.HTTP_10);
        } else if (protocolMB.equals("")) {
            // HTTP/0.9
            http09 = true;
            http11 = false;
            keepAlive = false;
        // ********** FIX FROM **********
        } else if (!protocolMB.startsWith("HTTP/")) {
            error = true;
            // 400 - Bas request
            response.setStatus(400);
        // ********** FIX TO **********
        } else {
            // Unsupported protocol
            http11 = false;
            error = true;
            // Send 505; Unsupported HTTP version
            response.setStatus(505);
        }
....
-----------------
2) for number 2 solution
org.apache.coyote.http11.Http11Processor#prepareResponse()
(line No.1530)
-----------------
    protected void prepareResponse() {

        boolean entityBody = true;
        contentDelimitation = 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) {
            response.addHeader("Connection", "Keep-Alive");
        // ********** FIX FROM **********
            error=false;
        // ********** FIX TO **********
        }
...
-----------------

regards,
Naru Hayashi from Japan
Comment 4 Naru Hayashi 2004-12-15 08:11:38 UTC
I am very very sorry REOPEN this bug.
This is a very small problem( not problem?). 
Although it does not mind even if this is not fixed, I want to know whether it 
will be fixed or not.
Naru Hayashi
Comment 5 william.barker 2004-12-15 08:17:41 UTC
Fixed in the CVS.