Author: markt Date: Thu Jun 28 07:55:13 2012 New Revision: 1354847 URL: http://svn.apache.org/viewvc?rev=1354847&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53454 Return correct content-length header for HEAD requests when value is > 2GB
Added: tomcat/trunk/test/javax/servlet/http/ tomcat/trunk/test/javax/servlet/http/TestHttpServlet.java (with props) Modified: tomcat/trunk/java/javax/servlet/http/HttpServlet.java tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Modified: tomcat/trunk/java/javax/servlet/http/HttpServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/http/HttpServlet.java?rev=1354847&r1=1354846&r2=1354847&view=diff ============================================================================== --- tomcat/trunk/java/javax/servlet/http/HttpServlet.java (original) +++ tomcat/trunk/java/javax/servlet/http/HttpServlet.java Thu Jun 28 07:55:13 2012 @@ -758,6 +758,14 @@ class NoBodyResponse extends HttpServlet } @Override + public void setHeader(String name, String value) { + super.setHeader(name, value); + if ("content-length".equalsIgnoreCase(name)) { + didSetContentLength = true; + } + } + + @Override public ServletOutputStream getOutputStream() throws IOException { return noBody; } Added: tomcat/trunk/test/javax/servlet/http/TestHttpServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/javax/servlet/http/TestHttpServlet.java?rev=1354847&view=auto ============================================================================== --- tomcat/trunk/test/javax/servlet/http/TestHttpServlet.java (added) +++ tomcat/trunk/test/javax/servlet/http/TestHttpServlet.java Thu Jun 28 07:55:13 2012 @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package javax.servlet.http; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.core.StandardContext; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; + +public class TestHttpServlet extends TomcatBaseTest { + + @Test + public void testBug53454() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + // Must have a real docBase - just use temp + StandardContext ctx = (StandardContext) + tomcat.addContext("", System.getProperty("java.io.tmpdir")); + + // Map the test Servlet + LargeBodyServlet largeBodyServlet = new LargeBodyServlet(); + Tomcat.addServlet(ctx, "largeBodyServlet", largeBodyServlet); + ctx.addServletMapping("/", "largeBodyServlet"); + + tomcat.start(); + + Map<String,List<String>> resHeaders= + new HashMap<String, List<String>>(); + int rc = headUrl("http://localhost:" + getPort() + "/", new ByteChunk(), + resHeaders); + + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + Assert.assertEquals(LargeBodyServlet.RESPONSE_LENGTH, + resHeaders.get("Content-Length").get(0)); + } + + + private static class LargeBodyServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + private static final String RESPONSE_LENGTH = "12345678901"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.setHeader("content-length", RESPONSE_LENGTH); + } + } +} Propchange: tomcat/trunk/test/javax/servlet/http/TestHttpServlet.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=1354847&r1=1354846&r2=1354847&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original) +++ tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Thu Jun 28 07:55:13 2012 @@ -200,6 +200,11 @@ public abstract class TomcatBaseTest ext return getUrl(path, out, null, resHead); } + public static int headUrl(String path, ByteChunk out, + Map<String, List<String>> resHead) throws IOException { + return methodUrl(path, out, 1000000, null, resHead, "HEAD"); + } + public static int getUrl(String path, ByteChunk out, Map<String, List<String>> reqHead, Map<String, List<String>> resHead) throws IOException { @@ -209,12 +214,20 @@ public abstract class TomcatBaseTest ext public static int getUrl(String path, ByteChunk out, int readTimeout, Map<String, List<String>> reqHead, Map<String, List<String>> resHead) throws IOException { + return methodUrl(path, out, readTimeout, reqHead, resHead, "GET"); + } + + public static int methodUrl(String path, ByteChunk out, int readTimeout, + Map<String, List<String>> reqHead, + Map<String, List<String>> resHead, + String method) throws IOException { URL url = new URL(path); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setUseCaches(false); connection.setReadTimeout(readTimeout); + connection.setRequestMethod(method); if (reqHead != null) { for (Map.Entry<String, List<String>> entry : reqHead.entrySet()) { StringBuilder valueList = new StringBuilder(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org