Permalink
Browse files

Reverted to netty 3.1.5 ga

Improvement
  • Loading branch information...
1 parent 3bfcb19 commit 916de494a9a99758245ca23a5d3c16c1051ae5fc @pepite pepite committed Mar 3, 2010
View
BIN lib/netty-3.2.0.ALPHA4-sources.jar
Binary file not shown.
View
BIN lib/netty-3.2.0.ALPHA4.jar
Binary file not shown.
View
3 src/play/modules/netty/FileChannelBuffer.java
@@ -314,4 +314,7 @@ public void readBytes(OutputStream out, int length) throws IOException {
getBytes(0, out, length);
}
+ public String toString(int q,int a,java.lang.String b) {
+ return null;
+ }
}
View
11 src/play/modules/netty/HttpServerPipelineFactory.java
@@ -19,15 +19,20 @@ public ChannelPipeline getPipeline() throws Exception {
max = Integer.MAX_VALUE;
}
+ Integer threshold = Integer.valueOf(Play.configuration.getProperty("play.module.netty.threshold", "8192"));
+ if (max == -1) {
+ max = Integer.MAX_VALUE;
+ }
+
ChannelPipeline pipeline = pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
-
-
- pipeline.addLast("streamer", new ChunkedWriteHandler());
pipeline.addLast("aggregator", new StreamChunkAggregator(max));
+ //pipeline.addLast("aggregator", new HttpChunkAggregator(max));
+ pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
+
pipeline.addLast("handler", new PlayHandler());
return pipeline;
View
176 src/play/modules/netty/PlayHandler.java
@@ -12,8 +12,7 @@
import play.Logger;
import play.Play;
import play.PlayPlugin;
-import play.data.validation.*;
-import play.data.validation.Error;
+import play.data.validation.Validation;
import play.exceptions.PlayException;
import play.exceptions.UnexpectedException;
import play.i18n.Messages;
@@ -32,11 +31,11 @@
import java.io.*;
import java.net.URI;
-import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.*;
-import java.util.regex.Matcher;
+
+import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.*;
@ChannelPipelineCoverage("one")
@@ -68,7 +67,7 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
Invoker.invoke(new NettyInvocation(request, response, ctx, nettyRequest));
}
} catch (Exception ex) {
- serve500(ex, ctx);
+ serve500(ex, ctx, nettyRequest);
return;
}
}
@@ -110,7 +109,7 @@ public boolean init() {
try {
Router.routeOnlyStatic(request);
} catch (NotFound e) {
- serve404(e, ctx, request);
+ serve404(e, ctx, request, nettyRequest);
return false;
} catch (RenderStatic e) {
if (Play.mode == Play.Mode.PROD) {
@@ -130,7 +129,7 @@ public void run() {
super.run();
} catch (Exception e) {
e.printStackTrace();
- serve500(e, ctx);
+ serve500(e, ctx, nettyRequest);
}
}
@@ -155,7 +154,7 @@ void saveExceededSizeError(HttpRequest nettyRequest, Response response) {
error.append(Messages.get(warning, length));
error.append("\u0000");
if (response.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS") != null && response.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS").value != null) {
- error.append(response.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS").value);
+ error.append(response.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS").value);
}
String errorData = URLEncoder.encode(error.toString(), "utf-8");
response.setCookie(Scope.COOKIE_PREFIX + "_ERRORS", errorData);
@@ -176,7 +175,6 @@ protected static void addToResponse(Response response, HttpResponse nettyRespons
CookieEncoder encoder = new CookieEncoder(true);
Map<String, Http.Cookie> cookies = response.cookies;
for (Http.Cookie cookie : cookies.values()) {
-
Cookie c = new DefaultCookie(cookie.name, cookie.value);
c.setSecure(cookie.secure);
c.setPath(cookie.path);
@@ -187,34 +185,55 @@ protected static void addToResponse(Response response, HttpResponse nettyRespons
c.setMaxAge(cookie.maxAge);
}
encoder.addCookie(c);
- nettyResponse.addHeader("Set-Cookie", encoder.encode());
}
-
- if (!response.headers.containsKey("cache-control") && !response.headers.containsKey("Cache-Control")) {
- nettyResponse.setHeader("Cache-Control", "no-cache");
+ if (!cookies.isEmpty()) {
+ nettyResponse.addHeader(SET_COOKIE, encoder.encode());
+ }
+ if (!response.headers.containsKey(CACHE_CONTROL)) {
+ nettyResponse.setHeader(CACHE_CONTROL, "no-cache");
}
}
- protected static void writeResponse(ChannelHandlerContext ctx, Response response, HttpResponse nettyResponse, HttpRequest nettyRequest) throws IOException {
- ChannelBuffer buf = ChannelBuffers.copiedBuffer(response.out.toByteArray());
- response.out.close();
+ protected static void writeResponse(ChannelHandlerContext ctx, Response response, HttpResponse nettyResponse, HttpRequest nettyRequest, boolean close) throws IOException {
+ byte[] content = response.out.toByteArray();
+ ChannelBuffer buf = ChannelBuffers.copiedBuffer(content);
nettyResponse.setContent(buf);
ChannelFuture f = ctx.getChannel().write(nettyResponse);
- f.addListener(ChannelFutureListener.CLOSE);
+ //if (close) {
+ // Close the connection when the whole content is written out.
+ f.addListener(ChannelFutureListener.CLOSE);
+ //}
}
public static void copyResponse(ChannelHandlerContext ctx, Request request, Response response, HttpRequest nettyRequest) throws Exception {
response.out.flush();
+
+ // Decide whether to close the connection or not.
+ boolean http10 = nettyRequest.getProtocolVersion().equals(HttpVersion.HTTP_1_0);
+ boolean close =
+ HttpHeaders.Values.CLOSE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION)) ||
+ (http10 && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION)));
+
+ // Build the response object.
+// org.jboss.netty.handler.codec.http.HttpResponse nettyResponse;
+// if (http10) {
+// nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.valueOf(response.status));
+// if (!close) {
+// nettyResponse.addHeader(HttpHeaders.Names.CONNECTION, "Keep-Alive");
+// }
+// } else {
+// nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.status));
+// }
HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.status));
- nettyResponse.setHeader("Server", signature);
+ nettyResponse.setHeader(SERVER, signature);
if (response.contentType != null) {
- nettyResponse.setHeader("Content-Type", response.contentType + (response.contentType.startsWith("text/") && !response.contentType.contains("charset") ? "; charset=utf-8" : ""));
+ nettyResponse.setHeader(CONTENT_TYPE, response.contentType + (response.contentType.startsWith("text/") && !response.contentType.contains("charset") ? "; charset=utf-8" : ""));
} else {
- nettyResponse.setHeader("Content-Type", "text/plain; charset=utf-8");
+ nettyResponse.setHeader(CONTENT_TYPE, "text/plain; charset=utf-8");
}
addToResponse(response, nettyResponse);
@@ -229,47 +248,29 @@ public static void copyResponse(ChannelHandlerContext ctx, Request request, Resp
}
if ((file != null) && file.isFile()) {
-
try {
addEtag(request, nettyResponse, file);
nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(file.length()));
ctx.getChannel().write(nettyResponse);
ChannelFuture writeFuture = ctx.getChannel().write(new ChunkedNioFile(file));
- // Decide whether to close the connection or not.
- // Comment out for now as it does not seem to work with Opera and IE
-// boolean close =
-// HttpHeaders.Values.CLOSE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION)) ||
-// nettyRequest.getProtocolVersion().equals(HttpVersion.HTTP_1_0) &&
-// !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION));
-//
-// if (close) {
+ //if (close) {
// Close the connection when the whole content is written out.
writeFuture.addListener(ChannelFutureListener.CLOSE);
//}
-
-
} catch (Exception e) {
- e.printStackTrace();
throw e;
}
} else if (is != null) {
ctx.getChannel().write(nettyResponse);
ChannelFuture writeFuture = ctx.getChannel().write(new ChunkedStream(is));
- // Comment out for now as it does not seem to work with Opera and IE
- // Decide whether to close the connection or not.
-// boolean close =
-// HttpHeaders.Values.CLOSE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION)) ||
-// nettyRequest.getProtocolVersion().equals(HttpVersion.HTTP_1_0) &&
-// !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION));
-//
-// if (close) {
+ //if (close) {
// Close the connection when the whole content is written out.
writeFuture.addListener(ChannelFutureListener.CLOSE);
- // }
+ //}
} else {
- writeResponse(ctx, response, nettyResponse, nettyRequest);
+ writeResponse(ctx, response, nettyResponse, nettyRequest, close);
}
}
@@ -289,19 +290,21 @@ public static Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyR
request.path = uri.getPath();
request.querystring = uri.getQuery() == null ? "" : uri.getQuery();
- final String contentType = nettyRequest.getHeader("Content-Type");
+ final String contentType = nettyRequest.getHeader(CONTENT_TYPE);
if (contentType != null) {
request.contentType = contentType.split(";")[0].trim().toLowerCase();
} else {
request.contentType = "text/html";
}
ChannelBuffer b = nettyRequest.getContent();
+
if (b instanceof FileChannelBuffer) {
FileChannelBuffer buffer = (FileChannelBuffer) nettyRequest.getContent();
// An error occured
Integer max = Integer.valueOf(Play.configuration.getProperty("play.module.netty.maxContentLength", "-1"));
- if (max == -1 || buffer.getInputStream().available() < max) {
+ if (max == -1 || buffer.getInputStream().available() < max) {
+
request.body = buffer.getInputStream();
} else {
request.body = new ByteArrayInputStream(new byte[0]);
@@ -312,7 +315,7 @@ public static Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyR
}
request.url = uri.toASCIIString();
- request.host = nettyRequest.getHeader("host");
+ request.host = nettyRequest.getHeader(HOST);
if (request.host.contains(":")) {
final String[] host = request.host.split(":");
@@ -386,19 +389,18 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
e.getChannel().close();
}
- public static void serve404(NotFound e, ChannelHandlerContext ctx, Request request) {
+ public static void serve404(NotFound e, ChannelHandlerContext ctx, Request request, HttpRequest nettyRequest) {
HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
- nettyResponse.setHeader("Server", signature);
+ nettyResponse.setHeader(SERVER, signature);
- nettyResponse.setHeader("Content-Type", "text/html");
+ nettyResponse.setHeader(CONTENT_TYPE, "text/html");
Map<String, Object> binding = getBindingForErrors(e, false);
String format = Request.current().format;
if (format == null || ("XMLHttpRequest".equals(request.headers.get("x-requested-with")) && "html".equals(format))) {
format = "txt";
}
- // TODO: is that correct? xxx.?
- nettyResponse.setHeader("Content-Type", (MimeTypes.getContentType("xxx." + format, "text/plain")));
+ nettyResponse.setHeader(CONTENT_TYPE, (MimeTypes.getContentType("404." + format, "text/plain")));
String errorHtml = TemplateLoader.load("errors/404." + format).render(binding);
@@ -435,10 +437,10 @@ public static void serve404(NotFound e, ChannelHandlerContext ctx, Request reque
}
// TODO: add request and response as parameter
- public static void serve500(Exception e, ChannelHandlerContext ctx) {
+ public static void serve500(Exception e, ChannelHandlerContext ctx, HttpRequest nettyRequest) {
HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
- nettyResponse.setHeader("Server", signature);
+ nettyResponse.setHeader(SERVER, signature);
Request request = Request.current();
Response response = Response.current();
@@ -464,8 +466,10 @@ public static void serve500(Exception e, ChannelHandlerContext ctx) {
}
encoder.addCookie(c);
}
-
- nettyResponse.setHeader("Cookie", encoder.encode());
+ if (!cookies.isEmpty()) {
+ nettyResponse.addHeader(SET_COOKIE, encoder.encode());
+ }
+ //nettyResponse.setHeader("Cookie", encoder.encode());
} catch (Exception exx) {
Logger.error(e, "Trying to flush cookies");
// humm ?
@@ -478,7 +482,7 @@ public static void serve500(Exception e, ChannelHandlerContext ctx) {
}
// TODO: is that correct? xxx.?
- nettyResponse.setHeader("Content-Type", (MimeTypes.getContentType("xxx." + format, "text/plain")));
+ nettyResponse.setHeader("Content-Type", (MimeTypes.getContentType("500." + format, "text/plain")));
try {
String errorHtml = TemplateLoader.load("errors/500." + format).render(binding);
@@ -516,8 +520,24 @@ public static void serve500(Exception e, ChannelHandlerContext ctx) {
}
public static void serveStatic(RenderStatic renderStatic, ChannelHandlerContext ctx, Request request, Response response, HttpRequest nettyRequest) {
- HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
- nettyResponse.setHeader("Server", signature);
+ // Decide whether to close the connection or not.
+// boolean http10 = nettyRequest.getProtocolVersion().equals(HttpVersion.HTTP_1_0);
+// boolean close =
+// HttpHeaders.Values.CLOSE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION)) ||
+// (http10 && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION)));
+
+ // Build the response object.
+// org.jboss.netty.handler.codec.http.HttpResponse nettyResponse;
+// if (http10) {
+// nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.valueOf(response.status));
+// if (!close) {
+// nettyResponse.addHeader(HttpHeaders.Names.CONNECTION, "Keep-Alive");
+// }
+// } else {
+// nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.status));
+// }
+ HttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.status));
+ nettyResponse.setHeader("Server", signature);
try {
VirtualFile file = Play.getVirtualFile(renderStatic.file);
if (file != null && file.exists() && file.isDirectory()) {
@@ -527,7 +547,7 @@ public static void serveStatic(RenderStatic renderStatic, ChannelHandlerContext
}
}
if ((file == null || !file.exists())) {
- serve404(new NotFound("The file " + renderStatic.file + " does not exist"), ctx, request);
+ serve404(new NotFound("The file " + renderStatic.file + " does not exist"), ctx, request, nettyRequest);
} else {
boolean raw = false;
for (PlayPlugin plugin : Play.plugins) {
@@ -541,19 +561,13 @@ public static void serveStatic(RenderStatic renderStatic, ChannelHandlerContext
} else {
addEtag(request, nettyResponse, file.getRealFile());
nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(file.length()));
+ nettyResponse.setHeader(CONTENT_TYPE, (MimeTypes.getContentType(file.getName(), "text/plain")));
ctx.getChannel().write(nettyResponse);
ChannelFuture writeFuture = ctx.getChannel().write(new ChunkedNioFile(file.getRealFile()));
- // Decide whether to close the connection or not.
- // Decide whether to close the connection or not.
-// boolean close =
-// HttpHeaders.Values.CLOSE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION)) ||
-// nettyRequest.getProtocolVersion().equals(HttpVersion.HTTP_1_0) &&
-// !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(nettyRequest.getHeader(HttpHeaders.Names.CONNECTION));
-//
-// if (close) {
+ ///if (close) {
// Close the connection when the whole content is written out.
writeFuture.addListener(ChannelFutureListener.CLOSE);
- // }
+ //}
}
}
@@ -571,16 +585,16 @@ public static void serveStatic(RenderStatic renderStatic, ChannelHandlerContext
}
public static boolean isModified(String etag, long last, Request request) {
- if (request.headers.containsKey("If-None-Match")) {
- final String browserEtag = request.headers.get("If-None-Match").value();
+ if (request.headers.containsKey(IF_NONE_MATCH)) {
+ final String browserEtag = request.headers.get(IF_NONE_MATCH).value();
if (browserEtag.equals(etag)) {
return false;
}
return true;
}
- if (request.headers.containsKey("If-Modified-Since")) {
- final String ifModifiedSince = request.headers.get("If-Modified-Since").value();
+ if (request.headers.containsKey(IF_MODIFIED_SINCE)) {
+ final String ifModifiedSince = request.headers.get(IF_MODIFIED_SINCE).value();
if (!StringUtils.isEmpty(ifModifiedSince)) {
try {
@@ -597,33 +611,33 @@ public static boolean isModified(String etag, long last, Request request) {
return true;
}
- private static void addEtag(Request request, HttpResponse minaResponse, File file) throws IOException {
+ private static void addEtag(Request request, HttpResponse httpResponse, File file) throws IOException {
if (Play.mode == Play.Mode.DEV) {
- minaResponse.setHeader("Cache-Control", "no-cache");
+ httpResponse.setHeader(CACHE_CONTROL, "no-cache");
} else {
String maxAge = Play.configuration.getProperty("http.cacheControl", "3600");
if (maxAge.equals("0")) {
- minaResponse.setHeader("Cache-Control", "no-cache");
+ httpResponse.setHeader(CACHE_CONTROL, "no-cache");
} else {
- minaResponse.setHeader("Cache-Control", "max-age=" + maxAge);
+ httpResponse.setHeader(CACHE_CONTROL, "max-age=" + maxAge);
}
}
boolean useEtag = Play.configuration.getProperty("http.useETag", "true").equals("true");
long last = file.lastModified();
final String etag = "\"" + last + "-" + file.hashCode() + "\"";
if (!isModified(etag, last, request)) {
- minaResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_MODIFIED);
+ httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_MODIFIED);
if (useEtag) {
- minaResponse.setHeader("Etag", etag);
+ httpResponse.setHeader(ETAG, etag);
}
} else {
- minaResponse.setHeader("Last-Modified", Utils.getHttpDateFormatter().format(new Date(last)));
+ httpResponse.setHeader(LAST_MODIFIED, Utils.getHttpDateFormatter().format(new Date(last)));
if (useEtag) {
- minaResponse.setHeader("Etag", etag);
+ httpResponse.setHeader(ETAG, etag);
}
- minaResponse.setHeader("Content-Type", MimeTypes.getContentType(file.getName()));
- minaResponse.setHeader("Content-Length", "" + file.length());
+ httpResponse.setHeader(CONTENT_TYPE, MimeTypes.getContentType(file.getName()));
+ httpResponse.setHeader(CONTENT_LENGTH, String.valueOf(file.length()));
}
}
View
63 src/play/modules/netty/StreamChunkAggregator.java
@@ -25,10 +25,7 @@
import org.apache.commons.io.IOUtils;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.jboss.netty.channel.*;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.HttpChunk;
import org.jboss.netty.handler.codec.http.HttpHeaders;
@@ -42,18 +39,18 @@
import java.util.List;
import java.util.UUID;
+@ChannelPipelineCoverage("one")
public class StreamChunkAggregator extends SimpleChannelUpstreamHandler {
private volatile HttpMessage currentMessage;
- private volatile String name;
+ private volatile BufferedWriter out;
private final int maxContentLength;
-
+ private volatile File file;
/**
* Creates a new instance.
*/
public StreamChunkAggregator(int maxContentLength) {
- super();
this.maxContentLength = maxContentLength;
}
@@ -67,8 +64,10 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
return;
}
- String localFile = this.name;
+
HttpMessage currentMessage = this.currentMessage;
+ BufferedWriter out = this.out;
+ File localFile = this.file;
if (currentMessage == null) {
HttpMessage m = (HttpMessage) msg;
if (m.isChunked()) {
@@ -83,43 +82,43 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
}
this.currentMessage = m;
- this.name = localName;
-
+ this.file = new File(Play.tmpDir, localName);
+ final FileWriter fstream = new FileWriter(file, true);
+ this.out = new BufferedWriter(fstream);
} else {
// Not a chunked message - pass through.
ctx.sendUpstream(e);
}
} else {
+ // TODO: If less that threshold then in memory
// Merge the received chunk into the content of the current message.
final HttpChunk chunk = (HttpChunk) msg;
- final File file = new File(Play.tmpDir, name);
- if (maxContentLength != -1 && (file.length() > (maxContentLength - chunk.getContent().readableBytes()))) {
- currentMessage.setHeader(
- HttpHeaders.Names.CONTENT_LENGTH, maxContentLength);
+ if (maxContentLength != -1 && (localFile.length() > (maxContentLength - chunk.getContent().readableBytes()))) {
+// currentMessage.addHeader(
+// HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(maxContentLength));
currentMessage.setHeader(
HttpHeaders.Names.WARNING, "play.netty.content.length.exceeded");
- return;
- }
-
- final FileWriter fstream = new FileWriter(file, true);
- final BufferedWriter out = new BufferedWriter(fstream);
-
- IOUtils.copy(new ByteArrayInputStream(chunk.getContent().array()), out);
- out.flush();
- out.close();
- fstream.close();
+ } else {
+ byte[] b = new byte[chunk.getContent().capacity()];
+ chunk.getContent().getBytes(0, b);
+ IOUtils.copy(new ByteArrayInputStream(b), out);
- if (chunk.isLast()) {
- currentMessage.setHeader(
- HttpHeaders.Names.CONTENT_LENGTH,
- String.valueOf(localFile.length()));
+ //fstream.close();
- currentMessage.setContent(new FileChannelBuffer(file));
+ if (chunk.isLast()) {
+ currentMessage.setHeader(
+ HttpHeaders.Names.CONTENT_LENGTH,
+ String.valueOf(localFile.length()));
- this.name = null;
- this.currentMessage = null;
- Channels.fireMessageReceived(ctx, currentMessage, e.getRemoteAddress());
+ currentMessage.setContent(new FileChannelBuffer(localFile));
+ out.flush();
+ out.close();
+ this.out = null;
+ this.currentMessage = null;
+ this.file = null;
+ Channels.fireMessageReceived(ctx, currentMessage, e.getRemoteAddress());
+ }
}
}

0 comments on commit 916de49

Please sign in to comment.