Bug 37794 - getParameter() fails on POST with transfer-encoding: chunked
getParameter() fails on POST with transfer-encoding: chunked
Status: RESOLVED FIXED
Product: Tomcat 5
Classification: Unclassified
Component: Servlet & JSP API
5.5.12
PC Windows 2000
: P2 normal with 3 votes (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2005-12-05 18:43 UTC by Arne Riiber
Modified: 2009-07-05 16:03 UTC (History)
1 user (show)



Attachments
Sample code for demonstrating the bug (10.83 KB, application/octet-stream)
2005-12-05 20:25 UTC, Arne Riiber
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Arne Riiber 2005-12-05 18:43:35 UTC
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
Comment 1 Remy Maucherat 2005-12-05 18:53:01 UTC
URL POST must use a content-length. Otherwise, it's something else.
Comment 2 Arne Riiber 2005-12-05 19:45:12 UTC
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

Comment 3 Arne Riiber 2005-12-05 20:25:59 UTC
Created attachment 17155 [details]
Sample code for demonstrating the bug
Comment 4 Rushabh Doshi 2007-01-24 15:37:40 UTC
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
Comment 5 MJ 2008-04-04 15:18:59 UTC
As of Tomcat 5.5.20 and Tomcat 6.0.16, this is still an open issue.  Any status?
Comment 6 Mark Thomas 2009-06-16 13:31:19 UTC
This has been fixed in trunk (with a test case) and will be proposed for 6.0.x and 5.5.x
Comment 7 Mark Thomas 2009-06-24 10:46:01 UTC
This has been fixed in 6.0.x and will be included in 6.0.21 onwards
Comment 8 Mark Thomas 2009-07-05 16:03:38 UTC
This has been fixed in 5.5.x and will be included in 5.5.28 onwards.