String contentTypeString = getHeader("Content-Type");
if (contentTypeString != null) {
//NOTE: only set charset parameter for "text/..." content types
//Otherwise some applications which expect an "application/..."
//content type will become confused.
ContentType ctype = ContentType.parse(contentTypeString);
if (ctype.getParameter("charset", null) == null
&& specified_charset != null) {
setHeader("Content-Type",
contentTypeString + "; charset=" + specified_charset);
}
}