From 7267bbee0a52f21ac1d7ba8ed085994d6802090f Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 7 Apr 2011 12:08:25 +0000 Subject: [PATCH] #6785, #6401: UIDL requests are now handled even though request does not know the content length svn changeset:18158/svn branch:6.5 --- .../server/AbstractCommunicationManager.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 4cad1cc8e6..152fa81bb5 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -1358,33 +1358,24 @@ public abstract class AbstractCommunicationManager implements protected String getRequestPayload(Request request) throws IOException { int requestLength = request.getContentLength(); - if (requestLength <= 0) { - /* - * TODO Browsers as we know them, know how long XHR they are sending - * and expose this in headers. However we have seen some -1 values - * in logs. Wild guess is that it is some kind of bot that tries to - * play well with ajax pages. Decide if we need to support those - * requests. See #6401 - */ + if (requestLength == 0) { return null; } - byte[] buffer = new byte[requestLength]; + ByteArrayOutputStream bout = requestLength <= 0 ? new ByteArrayOutputStream() + : new ByteArrayOutputStream(requestLength); + InputStream inputStream = request.getInputStream(); + byte[] buffer = new byte[MAX_BUFFER_SIZE]; - int bytesRemaining = requestLength; - while (bytesRemaining > 0) { - int bytesToRead = Math.min(bytesRemaining, MAX_BUFFER_SIZE); - int bytesRead = inputStream.read(buffer, requestLength - - bytesRemaining, bytesToRead); - if (bytesRead == -1) { + while (true) { + int read = inputStream.read(buffer); + if (read == -1) { break; } - - bytesRemaining -= bytesRead; + bout.write(buffer, 0, read); } - - String result = new String(buffer, "utf-8"); + String result = new String(bout.toByteArray(), "utf-8"); return result; } -- 2.39.5