You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2017/06/30 21:53:19 UTC
svn commit: r1800473 -
/tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
Author: markt
Date: Fri Jun 30 21:53:19 2017
New Revision: 1800473
URL: http://svn.apache.org/viewvc?rev=1800473&view=rev
Log:
Only attempt to convert character encoding for text resources
Modified:
tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.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=1800473&r1=1800472&r2=1800473&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Fri Jun 30 21:53:19 2017
@@ -937,12 +937,7 @@ public class DefaultServlet extends Http
} catch (IllegalStateException e) {
// If it fails, we try to get a Writer instead if we're
// trying to serve a text file
- if (!usingPrecompressedVersion &&
- ((contentType == null) ||
- (contentType.startsWith("text")) ||
- (contentType.endsWith("xml")) ||
- (contentType.contains("/javascript")))
- ) {
+ if (!usingPrecompressedVersion && isText(contentType)) {
writer = response.getWriter();
// Cannot reliably serve partial content with a Writer
ranges = FULL;
@@ -1017,7 +1012,7 @@ public class DefaultServlet extends Http
// Check to see if conversion is required
String outputEncoding = response.getCharacterEncoding();
Charset charset = B2CConverter.getCharset(outputEncoding);
- if (charset.equals(fileEncodingCharset)) {
+ if (!isText(contentType) || charset.equals(fileEncodingCharset)) {
if (!checkSendfile(request, response, resource,
contentLength, null)) {
// sendfile not possible so check if resource
@@ -1117,6 +1112,13 @@ public class DefaultServlet extends Http
}
}
+
+ private boolean isText(String contentType) {
+ return contentType == null || contentType.startsWith("text") ||
+ contentType.endsWith("xml") || contentType.contains("/javascript");
+ }
+
+
private boolean pathEndsWithCompressedExtension(String path) {
for (CompressionFormat format : compressionFormats) {
if (path.endsWith(format.extension)) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org