Fix bug where charset was always added to the Content-Type header even for binary responses. Now charset is only added if it was explicitly set via res.charset, or if the response was actually encoded using the given charset (i.e. writeBinary() wasn't used). Change default charset to UTF-8.
This commit is contained in:
parent
900a251d25
commit
51f31cac8a
2 changed files with 16 additions and 14 deletions
|
@ -643,8 +643,10 @@ public final class ResponseTrans extends Writer implements Serializable {
|
|||
/**
|
||||
* This has to be called after writing to this response has finished and before it is shipped back to the
|
||||
* web server. Transforms the string buffer into a byte array for transmission.
|
||||
* @param defaultCharset the charset to use if no explicit charset has been set on the response
|
||||
* @throws UnsupportedEncodingException if the charset is not a valid encoding name
|
||||
*/
|
||||
public synchronized void close(String cset) throws UnsupportedEncodingException {
|
||||
public synchronized void close(String defaultCharset) throws UnsupportedEncodingException {
|
||||
// if the response was already written and committed by the application
|
||||
// there's no point in closing the response buffer
|
||||
HttpServletResponse res = reqtrans.getServletResponse();
|
||||
|
@ -657,21 +659,20 @@ public final class ResponseTrans extends Writer implements Serializable {
|
|||
return;
|
||||
}
|
||||
|
||||
// only use default charset if not explicitly set for this response.
|
||||
if (charset == null) {
|
||||
charset = cset;
|
||||
}
|
||||
|
||||
// if charset is not set, use western encoding
|
||||
if (charset == null) {
|
||||
charset = "ISO-8859-1";
|
||||
}
|
||||
|
||||
boolean encodingError = false;
|
||||
|
||||
// only close if the response hasn't been closed yet, and if no
|
||||
// response was generated using writeBinary().
|
||||
if (response == null) {
|
||||
// only use default charset if not explicitly set for this response.
|
||||
if (charset == null) {
|
||||
charset = defaultCharset;
|
||||
}
|
||||
// if charset is not set, use western encoding
|
||||
if (charset == null) {
|
||||
charset = "UTF-8";
|
||||
}
|
||||
|
||||
// if debug buffer exists, append it to main buffer
|
||||
if (contentType != null &&
|
||||
contentType.startsWith("text/html") &&
|
||||
|
@ -719,8 +720,9 @@ public final class ResponseTrans extends Writer implements Serializable {
|
|||
response = new byte[0];
|
||||
notModified = true;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
// Etag creation failed for some reason. Ignore.
|
||||
} catch (Exception e) {
|
||||
// Etag creation failed for some reason.
|
||||
app.logError("Error creating ETag: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1822,7 +1822,7 @@ public final class Application implements Runnable {
|
|||
props.update();
|
||||
|
||||
// character encoding to be used for responses
|
||||
charset = props.getProperty("charset", "ISO-8859-1");
|
||||
charset = props.getProperty("charset", "UTF-8");
|
||||
|
||||
// debug flag
|
||||
debug = "true".equalsIgnoreCase(props.getProperty("debug"));
|
||||
|
|
Loading…
Add table
Reference in a new issue