From bf4e325ac6387cac0afc8096b3ca65b88bf9fdfd Mon Sep 17 00:00:00 2001 From: Fabian Lange Date: Mon, 24 Nov 2014 12:11:08 +0100 Subject: 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 --- .../vaadin/server/communication/UIInitHandler.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'server/src/com') 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; } -- cgit v1.2.3