Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[#1374] add support for very large uploads by exposing the unbuffered request inputstream #434

Closed
wants to merge 1 commit into from

2 participants

@pepite
Owner

Thanks but it would be nice to update the documentation accordingly otherwise no one will ever use this feature....

@pepite
Owner

See ticket. Cannot merge it anymore.

@pepite pepite closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 11, 2012
  1. @ets
This page is out of date. Refresh to see the latest.
View
13 framework/src/play/data/parsing/DirectStreamingParser.java
@@ -0,0 +1,13 @@
+package play.data.parsing;
+
+import java.io.InputStream;
+import java.util.Map;
+
+public class DirectStreamingParser extends DataParser {
+
+ @Override
+ public Map<String, String[]> parse(InputStream is) {
+ throw new UnsupportedOperationException("Requests exposing a direct InputStream should not be parsed.");
+ }
+
+}
View
24 framework/src/play/server/PlayHandler.java
@@ -15,10 +15,13 @@
import org.jboss.netty.handler.stream.ChunkedInput;
import org.jboss.netty.handler.stream.ChunkedStream;
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
+
import play.Invoker;
import play.Invoker.InvocationContext;
import play.Logger;
import play.Play;
+import play.data.parsing.DataParser;
+import play.data.parsing.DirectStreamingParser;
import play.data.validation.Validation;
import play.exceptions.PlayException;
import play.exceptions.UnexpectedException;
@@ -516,7 +519,7 @@ public Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyRequest,
Logger.trace("parseRequest: begin");
Logger.trace("parseRequest: URI = " + nettyRequest.getUri());
}
- final int index = nettyRequest.getUri().indexOf("?");
+
String uri = nettyRequest.getUri();
// Remove domain and port from URI if it's present.
if (uri.startsWith("http://") || uri.startsWith("https://")) {
@@ -563,10 +566,15 @@ public Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyRequest,
}
} else {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- IOUtils.copy(new ChannelBufferInputStream(b), out);
- byte[] n = out.toByteArray();
- body = new ByteArrayInputStream(n);
+ DataParser parser = DataParser.parsers.get(contentType);
+ if(parser instanceof DirectStreamingParser && (nettyRequest.getMethod().equals(HttpMethod.POST) || nettyRequest.getMethod().equals(HttpMethod.PUT)) ){
+ body = new ChannelBufferInputStream(b);
+ }else{
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(new ChannelBufferInputStream(b), out);
+ byte[] n = out.toByteArray();
+ body = new ByteArrayInputStream(n);
+ }
}
String host = nettyRequest.getHeader(HOST);
@@ -841,7 +849,7 @@ public void serveStatic(RenderStatic renderStatic, ChannelHandlerContext ctx, Re
if ((file == null || !file.exists())) {
serve404(new NotFound("The file " + renderStatic.file + " does not exist"), ctx, request, nettyRequest);
} else {
- boolean raw = Play.pluginCollection.serveStatic(file, request, response);
+ boolean raw = Play.pluginCollection.serveStatic(file, Request.current(), Response.current());
if (raw) {
copyResponse(ctx, request, response, nettyRequest);
} else {
@@ -1080,7 +1088,7 @@ protected void adjustPipelineToHixie(ChannelHandlerContext ctx) {
p.replace("encoder", "wsencoder", new WebSocketFrameEncoder());
}
- protected void adjustPipelineToHybi(ChannelHandlerContext ctx) {
+ protected void adjustPipelineToHybi(ChannelHandlerContext ctx) {
ChannelPipeline p = ctx.getChannel().getPipeline();
p.remove("aggregator");
p.replace("decoder", "wsdecoder", new Hybi10WebSocketFrameDecoder());
@@ -1340,4 +1348,4 @@ public void onSuccess() throws Exception {
super.onSuccess();
}
}
-}
+}
Something went wrong with that request. Please try again.