]> source.dussan.org Git - vaadin-framework.git/commitdiff
Include charset in text/html responses (#8777)
authorArtur <artur@vaadin.com>
Thu, 9 Mar 2017 12:50:46 +0000 (14:50 +0200)
committerHenri Sara <henri.sara@gmail.com>
Thu, 9 Mar 2017 12:50:46 +0000 (14:50 +0200)
Fixes #8775

server/src/main/java/com/vaadin/server/BootstrapHandler.java
server/src/main/java/com/vaadin/server/VaadinServlet.java
server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
server/src/main/java/com/vaadin/ui/LoginForm.java
shared/src/main/java/com/vaadin/shared/ApplicationConstants.java

index 74707842d8276e1e3ab9fc20859a194bc2e448d2..4619a89ce8518d4644275720c035f9521f03b7c4 100644 (file)
@@ -352,7 +352,8 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
 
     private void writeBootstrapPage(VaadinResponse response, String html)
             throws IOException {
-        response.setContentType("text/html");
+        response.setContentType(
+                ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
         BufferedWriter writer = new BufferedWriter(
                 new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
         writer.append(html);
@@ -372,8 +373,8 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
         document.child(0).before(doctype);
 
         Element head = document.head();
-        head.appendElement("meta").attr("http-equiv", "Content-Type")
-                .attr("content", "text/html; charset=utf-8");
+        head.appendElement("meta").attr("http-equiv", "Content-Type").attr(
+                "content", ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
 
         /*
          * Enable Chrome Frame in all versions of IE if installed.
index 3dfb5ba33c90d25db40fe49b6b25868a4f6a7a2e..f02ef444b975ce680d9f3d4ddca5c776fab211f5 100644 (file)
@@ -55,6 +55,7 @@ import com.vaadin.annotations.VaadinServletConfiguration;
 import com.vaadin.annotations.VaadinServletConfiguration.InitParameterName;
 import com.vaadin.sass.internal.ScssStylesheet;
 import com.vaadin.server.communication.ServletUIInitHandler;
+import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.shared.JsonConstants;
 import com.vaadin.shared.Version;
 import com.vaadin.ui.UI;
@@ -587,7 +588,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
                 output += "</a>";
             }
             getService().writeStringResponse(response,
-                    "text/html; charset=UTF-8", output);
+                    ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8, output);
         }
     }
 
index f205e28b7dc70c5e666aba37883c9b01c7912a66..6a19680da003fb07b4a29a235000bc2224018949 100644 (file)
@@ -36,6 +36,7 @@ import com.vaadin.server.UploadException;
 import com.vaadin.server.VaadinRequest;
 import com.vaadin.server.VaadinResponse;
 import com.vaadin.server.VaadinSession;
+import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.UI;
 import com.vaadin.ui.Upload.FailedEvent;
@@ -682,7 +683,8 @@ public class FileUploadHandler implements RequestHandler {
      */
     protected void sendUploadResponse(VaadinRequest request,
             VaadinResponse response) throws IOException {
-        response.setContentType("text/html");
+        response.setContentType(
+                ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
         final OutputStream out = response.getOutputStream();
         final PrintWriter outWriter = new PrintWriter(
                 new BufferedWriter(new OutputStreamWriter(out, "UTF-8")));
index 89244004db287234fd1fd0d0ab110acab5a31707..1a037ddfc8fba252e6231dfc9b2c6b9f155154b8 100644 (file)
@@ -25,6 +25,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import com.vaadin.server.StreamResource;
+import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.shared.ui.loginform.LoginFormConstants;
 import com.vaadin.shared.ui.loginform.LoginFormRpc;
 import com.vaadin.shared.ui.loginform.LoginFormState;
@@ -309,7 +310,7 @@ public class LoginForm extends AbstractSingleComponentContainer {
 
         StreamResource resource = new StreamResource(new LoginStreamSource(),
                 LoginFormConstants.LOGIN_RESOURCE_NAME);
-        resource.setMIMEType("text/html; charset=utf-8");
+        resource.setMIMEType(ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
         resource.setCacheTime(-1);
         setResource(LoginFormConstants.LOGIN_RESOURCE_NAME, resource);
 
index 142573ea1f1e2a909dfc248f5ad3ddfdf1a3e851..79a597b4f4bb1d568b40619ce7967bc6c3a3bdc3 100644 (file)
@@ -158,4 +158,9 @@ public class ApplicationConstants implements Serializable {
      */
     public static final String WIDGETSET_VERSION_ID = "wsver";
 
+    /**
+     * Content type to use for text/html responses (should always be UTF-8).
+     */
+    public static final String CONTENT_TYPE_TEXT_HTML_UTF_8 = "text/html; charset=utf-8";
+
 }