Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[#920] [#1043] [#1363] Fixes crlf and binary/encoding issues for writ…

…eChunk - thanks to unkx80 (Yee Fan Tan) and hakobera (Kazuyuki Honda)
  • Loading branch information...
commit 30859227e1a1bcad7958e8168a2b2debc438484d 1 parent aff952a
@mbknor mbknor authored
View
26 framework/src/play/server/PlayHandler.java
@@ -922,7 +922,7 @@ public static void setContentLength(HttpMessage message, long contentLength) {
static class LazyChunkedInput implements org.jboss.netty.handler.stream.ChunkedInput {
private boolean closed = false;
- private ConcurrentLinkedQueue<Object> nextChunks = new ConcurrentLinkedQueue<Object>();
+ private ConcurrentLinkedQueue<byte[]> nextChunks = new ConcurrentLinkedQueue<byte[]>();
public boolean hasNextChunk() throws Exception {
return !nextChunks.isEmpty();
@@ -932,7 +932,7 @@ public Object nextChunk() throws Exception {
if (nextChunks.isEmpty()) {
return null;
}
- return wrappedBuffer(((String) nextChunks.poll()).getBytes());
+ return wrappedBuffer(nextChunks.poll());
}
public boolean isEndOfInput() throws Exception {
@@ -941,17 +941,27 @@ public boolean isEndOfInput() throws Exception {
public void close() throws Exception {
if (!closed) {
- nextChunks.offer("0\r\n\r\n");
+ nextChunks.offer("0\r\n\r\n".getBytes());
}
closed = true;
}
public void writeChunk(Object chunk) throws Exception {
- String message = chunk == null ? "" : chunk.toString();
- StringWriter writer = new StringWriter();
- Integer l = message.getBytes(Response.current().encoding).length + 2;
- writer.append(Integer.toHexString(l)).append("\r\n").append(message).append("\r\n\r\n");
- nextChunks.offer(writer.toString());
+ byte[] bytes;
+ if ( chunk instanceof byte[]) {
+ bytes = (byte[])chunk;
+ } else {
+ String message = chunk == null ? "" : chunk.toString();
+ bytes = message.getBytes(Response.current().encoding);
+ }
+
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ byteStream.write(Integer.toHexString(bytes.length).getBytes());
+ final byte[] crlf = new byte[]{(byte)'\r', (byte)'\n'};
+ byteStream.write(crlf);
+ byteStream.write(bytes);
+ byteStream.write(crlf);
+ nextChunks.offer( byteStream.toByteArray());
}
}
View
11 samples-and-tests/just-test-cases/app/controllers/Application.java
@@ -2,6 +2,7 @@
import java.util.*;
import java.io.File;
+import java.io.UnsupportedEncodingException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -296,5 +297,15 @@ public static void selectTag(){
public static void fastTag_render_test() {
render();
}
+
+ public static void writeChunks() throws UnsupportedEncodingException {
+ response.contentType = "text/plain";
+ response.setHeader("Transfer-Encoding", "chunked");
+ response.writeChunk("a");
+ response.writeChunk("b");
+ response.writeChunk("c");
+ response.writeChunk("æøå");
+ response.writeChunk("æøå".getBytes("UTF-8"));
+ }
}
View
6 samples-and-tests/just-test-cases/test/chunked.test.html
@@ -0,0 +1,6 @@
+#{selenium 'Test chunked'}
+
+ open('/application/writeChunks')
+ assertTextPresent('abcæøåæøå')
+
+#{/selenium}
Please sign in to comment.
Something went wrong with that request. Please try again.