ChunkedOutputStream missing last CRLF (original) (raw)
Chris Hegarty chris.hegarty at oracle.com
Thu Feb 28 07:49:33 PST 2013
- Previous message: ChunkedOutputStream missing last CRLF
- Next message: RFR: 8009251 - Add proxy handling and keep-alive fixes to jsse
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Clearly sun.net.www.http.ChunkedOutpuStream is not a public API, so its direct use is not supported, or recommended.
Users of the HttpURLConnection API can only get indirect references to ChunkedOutputStream, and these are wrapped in a StreamingOutputStream [1]. The StreamingOutputStream.close will write the trailing CRLF.
-Chris.
On 02/28/2013 03:15 PM, Zhong Yu wrote:
HTTP chunked body should be ended with
0 CRLF CRLF See http://tools.ietf.org/html/rfc2616#section-3.6.1 However sun.net.www.http.ChunkedOutputStream ends only with 0 CRLF missing the last CRLF. This is a serious framing error. If an HTTP connection is reused, the next message head will be considered trailer for the chunked body and ignored, and the next message body will be parsed as head. If the HTTP connection is not reused, the other end may be waiting indefinitely for the chunked body to end. Test code: public static void main(String[] args) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ChunkedOutputStream chunked = new ChunkedOutputStream(new PrintStream(out)); chunked.close(); out.close(); for(byte b : out.toByteArray()) System.out.println(b); } produces "0 CR LF", while it should produce "0 CR LF CR LF". Zhong Yu
- Previous message: ChunkedOutputStream missing last CRLF
- Next message: RFR: 8009251 - Add proxy handling and keep-alive fixes to jsse
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]