https://bz.apache.org/bugzilla/show_bug.cgi?id=60698

            Bug ID: 60698
           Summary: getContentLength returns -1 for requests without body
           Product: Tomcat 7
           Version: 7.0.73
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Connectors
          Assignee: dev@tomcat.apache.org
          Reporter: tobias.oberl...@sap.com
  Target Milestone: ---

javax.servlet.ServletRequest.getContentLength() specifies that it would return
"an integer containing the length of the request body or -1 if the length is
not known". 

However Catalina's implementation of that method [1] also returns -1 for
requests without request body. IMHO this violates the specification because
because it is known that an attempt to read the request body will yield zero
bytes.

The root cause of this problem lies in the implementation of
org.apache.coyote.Request.getContentLengthLong(). This method only checks the
presence of the "content-length" header and returns -1 if that header is not
set. Instead, it should also test for the absence of the "transfer-encoding"
header, and return 0 if that header is absent.

This would then also be compliant with what is described in the section
"Message Body Length" in the HTTP standard [2]: "If this is a request message
and none of the above are true, then the message body length is zero (no
message body is present)."

[1] org.apache.catalina.connector.Request.getContentLength()
[2] https://tools.ietf.org/html/rfc7230#section-3.3.3

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to