Overview: When an HTTP/1.1 client (for example J2ME) POST with transfer-encoding: chunked to a servlet, the getParameter() family and getQueryString() methods fail to retrieve the correct result by returning nothing. In contrast, reading until end-of-file on the servlets input stream produces correct result. Steps to reproduce: Send a chunked POST request, with a=0 in the first chunk, sleep 1 s, then send &b=0 in the next, followed by a 0-chunk and trailer. On the receiving servlet, call getParameterNames() or getParameter(). Actual Results: null Expected results: a=0&b=1 Build: Tomcat 5.5.12 Additional Builds and Platforms: - getParameter() does fail on: Tomcat 4.1.18 Tomcat 4.1.24 Tomcat 5.5.12 - getParameter() doesn't fail on: Jetty 5.1.6 Additional Information: Please refer to the log below for Tomcat behaviour. It is from a simple test client and servlet written to demonstrate the bug. Tomcat 5.5.12 log: **************************** 1) Reading the body - PASS * **************************** [junit] // testChunked(localhost, 8080) [junit] // Sending request to host localhost port 8080 [junit] POST /testchunked/EchoServlet/getBody HTTP/1.1 [junit] User-Agent: no.riiber.net.http.test.chunked.EchoClient (chunked-test) [junit] content-type: application/x-www-form-urlencoded [junit] connection: Close [junit] host: localhost:8080 [junit] transfer-encoding: chunked [junit] 3 [junit] a=0 [junit] 4 [junit] &b=1 [junit] // Reading response from host localhost port 8080 [junit] HTTP/1.1 200 OK [junit] Server: Apache-Coyote/1.1 [junit] Content-Type: text/plain;charset=ISO-8859-1 [junit] Content-Length: 9 [junit] Date: Mon, 05 Dec 2005 07:48:59 GMT [junit] Connection: close [junit] a=0&b=1 [junit] // PASS: a=0 [junit] // PASS: &b=1 *************************************** 2) Reading using getQuerySTring: FAILS *************************************** [junit] // testChunked(localhost, 8080) [junit] // Sending request to host localhost port 8080 [junit] POST /testchunked/EchoServlet/getQueryString HTTP/1.1 [junit] User-Agent: no.riiber.net.http.test.chunked.EchoClient (chunked-test) [junit] content-type: application/x-www-form-urlencoded [junit] connection: Close [junit] host: localhost:8080 [junit] transfer-encoding: chunked [junit] 3 [junit] a=0 [junit] 4 [junit] &b=1 [junit] // Reading response from host localhost port 8080 [junit] HTTP/1.1 200 OK [junit] Server: Apache-Coyote/1.1 [junit] Content-Type: text/plain;charset=ISO-8859-1 [junit] Content-Length: 6 [junit] Date: Mon, 05 Dec 2005 07:48:59 GMT [junit] Connection: close [junit] null [junit] // *** FAIL: a=0 is not present in response from /testchunked/EchoServlet/getQueryString *** [junit] // *** FAIL: &b=1 is not present in response from /testchunked/EchoServlet/getQueryString *** ******************************************** 3) Reading using getParameterNames(): FAILS ********************************************* [junit] // testChunked(localhost, 8080) [junit] // Sending request to host localhost port 8080 [junit] POST /testchunked/EchoServlet/getParameterNamesAndValues HTTP/1.1 [junit] User-Agent: no.riiber.net.http.test.chunked.EchoClient (chunked-test) [junit] content-type: application/x-www-form-urlencoded [junit] connection: Close [junit] host: localhost:8080 [junit] transfer-encoding: chunked [junit] 3 [junit] a=0 [junit] 4 [junit] &b=1 [junit] // Reading response from host localhost port 8080 [junit] HTTP/1.1 200 OK [junit] Server: Apache-Coyote/1.1 [junit] Content-Type: text/plain;charset=ISO-8859-1 [junit] Content-Length: 2 [junit] Date: Mon, 05 Dec 2005 07:49:02 GMT [junit] Connection: close [junit] // *** FAIL: a=0 is not present in response from /testchunked/EchoServlet/getParameterNamesAndValues *** [junit] // *** FAIL: &b=1 is not present in response from /testchunked/EchoServlet/getParameterNamesAndValues *** Best regards Arne Riiber
URL POST must use a content-length. Otherwise, it's something else.
It's correct that Content-Length was required for HTTP/1.0, but with HTTP/1.1 it's not required anymore according to RFC2616 [ftp://ftp.isi.edu/in-notes/rfc2616.txt] chapter 4.3: The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request's message-headers. RFC2616 chapter 19.4.6 "Introduction of Transfer-Encoding" also includes pseudo code for determining the content-length from the chunks. Please correct me if I'm wrong. Best regards Arne Riiber
Created attachment 17155 [details] Sample code for demonstrating the bug
This is really a problem for any POST requests coming out of MIDP where you cannot change your transfer encoding (its controlled by the device). Thanks a lot, -Rushabh
As of Tomcat 5.5.20 and Tomcat 6.0.16, this is still an open issue. Any status?
This has been fixed in trunk (with a test case) and will be proposed for 6.0.x and 5.5.x
This has been fixed in 6.0.x and will be included in 6.0.21 onwards
This has been fixed in 5.5.x and will be included in 5.5.28 onwards.