Author: markt Date: Mon Jul 10 21:29:58 2017 New Revision: 1801540 URL: http://svn.apache.org/viewvc?rev=1801540&view=rev Log: Further 49464 fixes - precompression Update unit tests to avoid conversion
Added: tomcat/trunk/test/webapp/404.html (with props) Modified: tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java Modified: tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java?rev=1801540&r1=1801539&r2=1801540&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Mon Jul 10 21:29:58 2017 @@ -965,7 +965,8 @@ public class DefaultServlet extends Http String outputEncoding = response.getCharacterEncoding(); Charset charset = B2CConverter.getCharset(outputEncoding); boolean conversionRequired; - if (isText(contentType) && !charset.equals(fileEncodingCharset)) { + if (!usingPrecompressedVersion && isText(contentType) && + !charset.equals(fileEncodingCharset)) { conversionRequired = true; // Conversion often results fewer/more/different bytes. // That does not play nicely with range requests. Modified: tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java?rev=1801540&r1=1801539&r2=1801540&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java (original) +++ tomcat/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java Mon Jul 10 21:29:58 2017 @@ -54,6 +54,7 @@ import org.apache.catalina.startup.Tomca import org.apache.catalina.startup.TomcatBaseTest; import org.apache.tomcat.util.buf.B2CConverter; import org.apache.tomcat.util.buf.ByteChunk; +import org.apache.tomcat.util.descriptor.web.ErrorPage; import org.apache.tomcat.util.http.parser.MediaType; import org.apache.tomcat.websocket.server.WsContextListener; @@ -120,6 +121,7 @@ public class TestDefaultServlet extends Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default", "org.apache.catalina.servlets.DefaultServlet"); defaultServlet.addInitParameter("gzip", "true"); + defaultServlet.addInitParameter("fileEncoding", "ISO-8859-1"); ctxt.addServletMappingDecoded("/", "default"); ctxt.addMimeMapping("html", "text/html"); @@ -175,6 +177,7 @@ public class TestDefaultServlet extends Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default", "org.apache.catalina.servlets.DefaultServlet"); defaultServlet.addInitParameter("precompressed", "true"); + defaultServlet.addInitParameter("fileEncoding", "ISO-8859-1"); ctxt.addServletMappingDecoded("/", "default"); ctxt.addMimeMapping("html", "text/html"); @@ -285,6 +288,7 @@ public class TestDefaultServlet extends Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default", DefaultServlet.class.getName()); defaultServlet.addInitParameter("precompressed", "br=.br,gzip=.gz"); + defaultServlet.addInitParameter("fileEncoding", "ISO-8859-1"); ctxt.addServletMappingDecoded("/", "default"); ctxt.addMimeMapping("html", "text/html"); @@ -455,36 +459,24 @@ public class TestDefaultServlet extends */ @Test public void testCustomErrorPage() throws Exception { - File appDir = new File(getTemporaryDirectory(), "MyApp"); - File webInf = new File(appDir, "WEB-INF"); - addDeleteOnTearDown(appDir); - if (!webInf.mkdirs() && !webInf.isDirectory()) { - fail("Unable to create directory [" + webInf + "]"); - } - - File webxml = new File(appDir, "WEB-INF/web.xml"); - try (FileOutputStream fos = new FileOutputStream(webxml); - Writer w = new OutputStreamWriter(fos, "UTF-8")) { - w.write("<?xml version='1.0' encoding='UTF-8'?>\n" - + "<web-app xmlns='http://java.sun.com/xml/ns/j2ee' " - + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" - + " xsi:schemaLocation='http://java.sun.com/xml/ns/j2ee " - + " http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd'" - + " version='2.4'>\n" - + "<error-page>\n<error-code>404</error-code>\n" - + "<location>/404.html</location>\n</error-page>\n" - + "</web-app>\n"); - } - - File error404 = new File(appDir, "404.html"); - try (FileOutputStream fos = new FileOutputStream(error404); - Writer w = new OutputStreamWriter(fos, "ISO-8859-1")) { - w.write("It is 404.html"); - } Tomcat tomcat = getTomcatInstance(); - String contextPath = "/MyApp"; - tomcat.addWebapp(null, contextPath, appDir.getAbsolutePath()); + + File appDir = new File("test/webapp"); + + // app dir is relative to server home + Context ctxt = tomcat.addContext("", appDir.getAbsolutePath()); + Wrapper defaultServlet = Tomcat.addServlet(ctxt, "default", + DefaultServlet.class.getName()); + defaultServlet.addInitParameter("fileEncoding", "ISO-8859-1"); + + ctxt.addServletMappingDecoded("/", "default"); + ctxt.addMimeMapping("html", "text/html"); + ErrorPage ep = new ErrorPage(); + ep.setErrorCode(404); + ep.setLocation("/404.html"); + ctxt.addErrorPage(ep); + tomcat.start(); TestCustomErrorClient client = Added: tomcat/trunk/test/webapp/404.html URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/404.html?rev=1801540&view=auto ============================================================================== --- tomcat/trunk/test/webapp/404.html (added) +++ tomcat/trunk/test/webapp/404.html Mon Jul 10 21:29:58 2017 @@ -0,0 +1 @@ +It is 404.html \ No newline at end of file Propchange: tomcat/trunk/test/webapp/404.html ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org