From ee52769dea4ee3fab725f206a5061a9f31e55b50 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 6 Sep 2013 09:18:22 +1000 Subject: [PATCH] 416663 Content-length set by resourcehandler --- .../src/main/java/org/eclipse/jetty/server/Response.java | 6 +++--- .../org/eclipse/jetty/server/handler/ResourceHandler.java | 7 ++++--- .../java/org/eclipse/jetty/servlet/DefaultServlet.java | 1 - 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 6bf81cccca0..b1fa612447d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -135,10 +135,10 @@ public class Response implements HttpServletResponse Response response = _channel.getResponse(); String contentType = httpContent.getContentType(); if (contentType != null && !response.getHttpFields().containsKey(HttpHeader.CONTENT_TYPE.asString())) - response.getHttpFields().put(HttpHeader.CONTENT_TYPE, contentType); - + setContentType(contentType); + if (httpContent.getContentLength() > 0) - response.getHttpFields().putLongField(HttpHeader.CONTENT_LENGTH, httpContent.getContentLength()); + setLongContentLength(httpContent.getContentLength()); String lm = httpContent.getLastModified(); if (lm != null) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java index f3bc5df5071..d1e13ce35b5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java @@ -602,19 +602,20 @@ public class ResourceHandler extends HandlerWrapper HttpFields fields = ((Response)response).getHttpFields(); if (length>0) - fields.putLongField(HttpHeader.CONTENT_LENGTH,length); + ((Response)response).setLongContentLength(length); if (_cacheControl!=null) fields.put(HttpHeader.CACHE_CONTROL,_cacheControl); } else { - if (length>0) + if (length>Integer.MAX_VALUE) response.setHeader(HttpHeader.CONTENT_LENGTH.asString(),Long.toString(length)); + else if (length>0) + response.setContentLength((int)length); if (_cacheControl!=null) response.setHeader(HttpHeader.CACHE_CONTROL.asString(),_cacheControl.toString()); } - } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java index 4a32465a731..97f69b295ac 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java @@ -988,7 +988,6 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory else // Handle cached resource (resource).writeTo(multi,start,size); - } if (in!=null) in.close();