r9866 - in helma/helma/trunk/src/helma/framework: . core
[email protected] Thu, 10 Sep 2009 15:23:38 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090910132338.5F01B3D0E3@mia> |
Author: hannes
Date: 2009-09-10 15:23:38 +0200 (Thu, 10 Sep 2009)
New Revision: 9866
Modified:
helma/helma/trunk/src/helma/framework/ResponseTrans.java
helma/helma/trunk/src/helma/framework/core/Application.java
Log:
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.
Details at http://dev.helma.org/trac/helma/changeset/9866
Modified: helma/helma/trunk/src/helma/framework/ResponseTrans.java
===================================================================
--- helma/helma/trunk/src/helma/framework/ResponseTrans.java 2009-09-09 23:32:30 UTC (rev 9865)
+++ helma/helma/trunk/src/helma/framework/ResponseTrans.java 2009-09-10 13:23:38 UTC (rev 9866)
@@ -643,8 +643,10 @@
/**
* 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 @@
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 @@
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);
}
}
Modified: helma/helma/trunk/src/helma/framework/core/Application.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/Application.java 2009-09-09 23:32:30 UTC (rev 9865)
+++ helma/helma/trunk/src/helma/framework/core/Application.java 2009-09-10 13:23:38 UTC (rev 9866)
@@ -1822,7 +1822,7 @@
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"));