Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed netty

  • Loading branch information...
commit 4ae085140945dcfd4f9f7ed23e7afca667678710 1 parent 916de49
@pepite pepite authored
View
2  documentation/manual/home.textile
@@ -1,6 +1,6 @@
h1. Netty module
-p(note). **Warning! This version contains JBoss Netty 3.2 alpha 4. Be sure to remove the previous version of Netty in your module directory**
+p(note). **Warning! This version contains JBoss Netty 3.2.0 alpha 4. Be sure to remove the previous version of Netty in your module directory**
The netty module allows you to use JBoss Netty:http://jboss.org/netty as a play! server.
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
4 src/play/modules/netty/HttpServerPipelineFactory.java
@@ -27,12 +27,10 @@ public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
- pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("aggregator", new StreamChunkAggregator(max));
+ pipeline.addLast("encoder", new HttpResponseEncoder());
//pipeline.addLast("aggregator", new HttpChunkAggregator(max));
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
-
-
pipeline.addLast("handler", new PlayHandler());
return pipeline;
View
74 src/play/modules/netty/PlayHandler.java
@@ -172,9 +172,9 @@ protected static void addToResponse(Response response, HttpResponse nettyRespons
nettyResponse.setHeader(entry.getKey(), value);
}
}
- CookieEncoder encoder = new CookieEncoder(true);
Map<String, Http.Cookie> cookies = response.cookies;
for (Http.Cookie cookie : cookies.values()) {
+ CookieEncoder encoder = new CookieEncoder(true);
Cookie c = new DefaultCookie(cookie.name, cookie.value);
c.setSecure(cookie.secure);
c.setPath(cookie.path);
@@ -185,8 +185,6 @@ protected static void addToResponse(Response response, HttpResponse nettyRespons
c.setMaxAge(cookie.maxAge);
}
encoder.addCookie(c);
- }
- if (!cookies.isEmpty()) {
nettyResponse.addHeader(SET_COOKIE, encoder.encode());
}
if (!response.headers.containsKey(CACHE_CONTROL)) {
@@ -195,16 +193,13 @@ protected static void addToResponse(Response response, HttpResponse nettyRespons
}
- protected static void writeResponse(ChannelHandlerContext ctx, Response response, HttpResponse nettyResponse, HttpRequest nettyRequest, boolean close) throws IOException {
+ protected static void writeResponse(ChannelHandlerContext ctx, Response response, HttpResponse nettyResponse) throws IOException {
byte[] content = response.out.toByteArray();
ChannelBuffer buf = ChannelBuffers.copiedBuffer(content);
nettyResponse.setContent(buf);
ChannelFuture f = ctx.getChannel().write(nettyResponse);
- //if (close) {
- // Close the connection when the whole content is written out.
- f.addListener(ChannelFutureListener.CLOSE);
- //}
+ f.addListener(ChannelFutureListener.CLOSE);
}
@@ -212,21 +207,7 @@ public static void copyResponse(ChannelHandlerContext ctx, Request request, Resp
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);
@@ -253,24 +234,19 @@ public static void copyResponse(ChannelHandlerContext ctx, Request request, Resp
nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(file.length()));
ctx.getChannel().write(nettyResponse);
ChannelFuture writeFuture = ctx.getChannel().write(new ChunkedNioFile(file));
- //if (close) {
+ if (!nettyResponse.isKeepAlive()) {
// Close the connection when the whole content is written out.
writeFuture.addListener(ChannelFutureListener.CLOSE);
- //}
+ }
} catch (Exception e) {
throw e;
}
} else if (is != null) {
ctx.getChannel().write(nettyResponse);
ChannelFuture writeFuture = ctx.getChannel().write(new ChunkedStream(is));
- //if (close) {
- // Close the connection when the whole content is written out.
- writeFuture.addListener(ChannelFutureListener.CLOSE);
- //}
-
-
+ writeFuture.addListener(ChannelFutureListener.CLOSE);
} else {
- writeResponse(ctx, response, nettyResponse, nettyRequest, close);
+ writeResponse(ctx, response, nettyResponse);
}
}
@@ -298,7 +274,6 @@ public static Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyR
}
ChannelBuffer b = nettyRequest.getContent();
-
if (b instanceof FileChannelBuffer) {
FileChannelBuffer buffer = (FileChannelBuffer) nettyRequest.getContent();
// An error occured
@@ -363,10 +338,9 @@ protected static void addToRequest(HttpRequest nettyRequest, Request request) {
request.headers.put(hd.name, hd);
}
- String value = nettyRequest.getHeader("Cookie");
+ String value = nettyRequest.getHeader(COOKIE);
if (value != null) {
Set<Cookie> cookies = new CookieDecoder().decode(value);
-
if (cookies != null) {
for (Cookie cookie : cookies) {
Http.Cookie playCookie = new Http.Cookie();
@@ -452,9 +426,10 @@ public static void serve500(Exception e, ChannelHandlerContext ctx, HttpRequest
// Flush some cookies
try {
- CookieEncoder encoder = new CookieEncoder(true);
+
Map<String, Http.Cookie> cookies = response.cookies;
for (Http.Cookie cookie : cookies.values()) {
+ CookieEncoder encoder = new CookieEncoder(true);
Cookie c = new DefaultCookie(cookie.name, cookie.value);
c.setSecure(cookie.secure);
c.setPath(cookie.path);
@@ -465,8 +440,6 @@ public static void serve500(Exception e, ChannelHandlerContext ctx, HttpRequest
c.setMaxAge(cookie.maxAge);
}
encoder.addCookie(c);
- }
- if (!cookies.isEmpty()) {
nettyResponse.addHeader(SET_COOKIE, encoder.encode());
}
//nettyResponse.setHeader("Cookie", encoder.encode());
@@ -520,24 +493,8 @@ public static void serve500(Exception e, ChannelHandlerContext ctx, HttpRequest
}
public static void serveStatic(RenderStatic renderStatic, ChannelHandlerContext ctx, Request request, Response response, HttpRequest nettyRequest) {
- // 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);
+ 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()) {
@@ -564,10 +521,7 @@ public static void serveStatic(RenderStatic renderStatic, ChannelHandlerContext
nettyResponse.setHeader(CONTENT_TYPE, (MimeTypes.getContentType(file.getName(), "text/plain")));
ctx.getChannel().write(nettyResponse);
ChannelFuture writeFuture = ctx.getChannel().write(new ChunkedNioFile(file.getRealFile()));
- ///if (close) {
- // Close the connection when the whole content is written out.
- writeFuture.addListener(ChannelFutureListener.CLOSE);
- //}
+ writeFuture.addListener(ChannelFutureListener.CLOSE);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.