summaryrefslogtreecommitdiffstats
path: root/server/src/com
diff options
context:
space:
mode:
authorFabian Lange <lange.fabian@gmail.com>2014-11-24 12:11:08 +0100
committerLeif Åstrand <leif@vaadin.com>2014-12-05 08:37:05 +0000
commitbf4e325ac6387cac0afc8096b3ca65b88bf9fdfd (patch)
tree417eea63ab1bd50679b10a53d559bc2a0e6247db /server/src/com
parent66c3dd2bf87ac3b021365b7a7d89180fb4304d8c (diff)
downloadvaadin-framework-bf4e325ac6387cac0afc8096b3ca65b88bf9fdfd.tar.gz
vaadin-framework-bf4e325ac6387cac0afc8096b3ca65b88bf9fdfd.zip
UIInitHandler emits Content-Length when writing json response (#15271)
This prevents chunked-transfer mode and allows server infrastructure to decide correctly on things like compression which benefits from knowing a content length. Change-Id: I4e969e0874b506d0f61526662ee78418987937c4
Diffstat (limited to 'server/src/com')
-rw-r--r--server/src/com/vaadin/server/communication/UIInitHandler.java21
1 files changed, 8 insertions, 13 deletions
diff --git a/server/src/com/vaadin/server/communication/UIInitHandler.java b/server/src/com/vaadin/server/communication/UIInitHandler.java
index 8e61370d85..1216d2b689 100644
--- a/server/src/com/vaadin/server/communication/UIInitHandler.java
+++ b/server/src/com/vaadin/server/communication/UIInitHandler.java
@@ -17,7 +17,7 @@
package com.vaadin.server.communication;
import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.io.OutputStream;
import java.io.StringWriter;
import java.util.List;
import java.util.logging.Level;
@@ -110,18 +110,13 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler {
// iOS 6 Safari requires this (#9732)
response.setHeader("Cache-Control", "no-cache");
- // NOTE! GateIn requires, for some weird reason, getOutputStream
- // to be used instead of getWriter() (it seems to interpret
- // application/json as a binary content type)
- OutputStreamWriter outputWriter = new OutputStreamWriter(
- response.getOutputStream(), "UTF-8");
- try {
- outputWriter.write(json);
- // NOTE GateIn requires the buffers to be flushed to work
- outputWriter.flush();
- } finally {
- outputWriter.close();
- }
+ byte[] b = json.getBytes("UTF-8");
+ response.setHeader("Content-Length", String.valueOf(b.length));
+
+ OutputStream outputStream = response.getOutputStream();
+ outputStream.write(b);
+ // NOTE GateIn requires the buffers to be flushed to work
+ outputStream.flush();
return true;
}