Permalink
Browse files

Fixed the validation error of Netty max-content

  • Loading branch information...
1 parent a61415e commit 14329ec74e3cc2552c94c900dab1d8cd092392dd @wangyizhuo wangyizhuo committed with pepite Jul 1, 2010
Showing with 18 additions and 7 deletions.
  1. +18 −7 src/play/modules/netty/PlayHandler.java
@@ -51,6 +51,7 @@
import play.mvc.results.NotFound;
import play.mvc.results.RenderStatic;
import play.templates.TemplateLoader;
+import play.templates.JavaExtensions;
import play.utils.Utils;
import play.vfs.VirtualFile;
@@ -172,33 +173,43 @@ public void run() {
@Override
public void execute() throws Exception {
Logger.trace("execute: begin");
+ saveExceededSizeError(nettyRequest, request, response);
ActionInvoker.invoke(request, response);
- saveExceededSizeError(nettyRequest, response);
copyResponse(ctx, request, response, nettyRequest);
Logger.trace("execute: end");
}
}
- void saveExceededSizeError(HttpRequest nettyRequest, Response response) {
+ void saveExceededSizeError(HttpRequest nettyRequest, Request request, Response response) {
String warning = nettyRequest.getHeader(HttpHeaders.Names.WARNING);
String length = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_LENGTH);
if (warning != null) {
try {
StringBuilder error = new StringBuilder();
error.append("\u0000");
- error.append(warning);
+ // Cannot put warning which is play.netty.content.length.exceeded
+ // as Key as it will result error when printing error
+ error.append("play.netty.maxContentLength");
error.append(":");
- error.append(Messages.get(warning, length));
+ String size = null;
+ try {
+ size = JavaExtensions.formatSize(Long.parseLong(length));
+ } catch (Exception e){
+ size = length + " bytes";
+ }
+ error.append(Messages.get(warning, size));
+ error.append("\u0001");
+ error.append(size);
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);
+ if (request.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS") != null && request.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS").value != null) {
+ error.append(request.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS").value);
}
String errorData = URLEncoder.encode(error.toString(), "utf-8");
Http.Cookie c = new Http.Cookie();
c.value = errorData;
c.name = Scope.COOKIE_PREFIX + "_ERRORS";
- response.cookies.put(Scope.COOKIE_PREFIX + "_ERRORS", c);
+ request.cookies.put(Scope.COOKIE_PREFIX + "_ERRORS", c);
} catch (Exception e) {
throw new UnexpectedException("Error serialization problem", e);
}

0 comments on commit 14329ec

Please sign in to comment.