View | Details | Raw Unified | Return to bug 57601
Collapse All | Expand All

(-)a/java/org/apache/catalina/servlets/DefaultServlet.java (-2 / +4 lines)
Lines 39-44 import java.util.Iterator; Link Here
39
import java.util.Locale;
39
import java.util.Locale;
40
import java.util.StringTokenizer;
40
import java.util.StringTokenizer;
41
41
42
import javax.servlet.DispatcherType;
42
import javax.servlet.RequestDispatcher;
43
import javax.servlet.RequestDispatcher;
43
import javax.servlet.ServletContext;
44
import javax.servlet.ServletContext;
44
import javax.servlet.ServletException;
45
import javax.servlet.ServletException;
Lines 415-422 public class DefaultServlet extends HttpServlet { Link Here
415
                          HttpServletResponse response)
416
                          HttpServletResponse response)
416
        throws IOException, ServletException {
417
        throws IOException, ServletException {
417
418
418
        // Serve the requested resource, without the data content
419
        // Serve the requested resource, without the data content unless we are being included
419
        serveResource(request, response, false, fileEncoding);
420
        boolean serveContent = DispatcherType.INCLUDE.equals(request.getDispatcherType());
421
        serveResource(request, response, serveContent, fileEncoding);
420
422
421
    }
423
    }
422
424
(-)a/test/org/apache/catalina/servlets/TestDefaultServlet.java (+28 lines)
Lines 23-28 import java.io.OutputStreamWriter; Link Here
23
import java.io.Writer;
23
import java.io.Writer;
24
import java.text.SimpleDateFormat;
24
import java.text.SimpleDateFormat;
25
import java.util.Date;
25
import java.util.Date;
26
import java.util.HashMap;
26
import java.util.List;
27
import java.util.List;
27
import java.util.Locale;
28
import java.util.Locale;
28
import java.util.Map;
29
import java.util.Map;
Lines 35-40 import static org.junit.Assert.assertFalse; Link Here
35
import static org.junit.Assert.assertTrue;
36
import static org.junit.Assert.assertTrue;
36
import static org.junit.Assert.fail;
37
import static org.junit.Assert.fail;
37
38
39
import org.junit.Assert;
38
import org.junit.Test;
40
import org.junit.Test;
39
41
40
import static org.apache.catalina.startup.SimpleHttpClient.CRLF;
42
import static org.apache.catalina.startup.SimpleHttpClient.CRLF;
Lines 340-345 public class TestDefaultServlet extends TomcatBaseTest { Link Here
340
        assertTrue(client.isResponse404());
342
        assertTrue(client.isResponse404());
341
    }
343
    }
342
344
345
    /**
346
     * Verifies that the same Content-Length is returned for both GET and HEAD operations when a
347
     * static resource served by the DefaultServlet is included.
348
     */
349
    @Test
350
    public void testBug57601() throws Exception {
351
        Tomcat tomcat = getTomcatInstanceTestWebapp(false, true);
352
353
        Map<String,List<String>> resHeaders= new HashMap<>();
354
        String path = "http://localhost:" + getPort() + "/test/bug5nnnn/bug57601.jsp";
355
        ByteChunk out = new ByteChunk();
356
357
        int rc = getUrl(path, out, resHeaders);
358
        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
359
        String length = resHeaders.get("Content-Length").get(0);
360
        Assert.assertEquals(Long.parseLong(length), out.getLength());
361
        out.recycle();
362
363
        rc = headUrl(path, out, resHeaders);
364
        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
365
        Assert.assertEquals(0, out.getLength());
366
        Assert.assertEquals(length, resHeaders.get("Content-Length").get(0));
367
368
        tomcat.stop();
369
    }
370
343
    public static int getUrl(String path, ByteChunk out,
371
    public static int getUrl(String path, ByteChunk out,
344
            Map<String, List<String>> resHead) throws IOException {
372
            Map<String, List<String>> resHead) throws IOException {
345
        out.recycle();
373
        out.recycle();
(-)a/test/webapp/bug5nnnn/bug57601.jsp (+18 lines)
Line 0 Link Here
1
<%--
2
  Licensed to the Apache Software Foundation (ASF) under one or more
3
  contributor license agreements.  See the NOTICE file distributed with
4
  this work for additional information regarding copyright ownership.
5
  The ASF licenses this file to You under the Apache License, Version 2.0
6
  (the "License"); you may not use this file except in compliance with
7
  the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
  Unless required by applicable law or agreed to in writing, software
12
  distributed under the License is distributed on an "AS IS" BASIS,
13
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
  See the License for the specific language governing permissions and
15
  limitations under the License.
16
  --%>
17
Outer
18
<jsp:include page="bug57601.txt"/>
(-)a/test/webapp/bug5nnnn/bug57601.txt (+16 lines)
Line 0 Link Here
1
#  Licensed to the Apache Software Foundation (ASF) under one or more
2
#  contributor license agreements.  See the NOTICE file distributed with
3
#  this work for additional information regarding copyright ownership.
4
#  The ASF licenses this file to You under the Apache License, Version 2.0
5
#  (the "License"); you may not use this file except in compliance with
6
#  the License.  You may obtain a copy of the License at
7
#
8
#       http://www.apache.org/licenses/LICENSE-2.0
9
#
10
#  Unless required by applicable law or agreed to in writing, software
11
#  distributed under the License is distributed on an "AS IS" BASIS,
12
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
#  See the License for the specific language governing permissions and
14
#  limitations under the License.
15
16
Inner

Return to bug 57601