summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorFabian Lange <lange.fabian@gmail.com>2014-11-24 12:11:08 +0100
committerSauli Tähkäpää <sauli@vaadin.com>2014-12-09 12:18:24 +0200
commit74162f281ec5ada2278bcdabef469f12c167e41b (patch)
tree764033ca96939cd84b26b54f386c7ba19390ea36 /server
parent16cb0d22809f2897ec88fc80068deb5e0ef8c174 (diff)
downloadvaadin-framework-74162f281ec5ada2278bcdabef469f12c167e41b.tar.gz
vaadin-framework-74162f281ec5ada2278bcdabef469f12c167e41b.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')
-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 cf0de8e9ee..d0b9aaaf15 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;
@@ -114,18 +114,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;
}