]> source.dussan.org Git - vaadin-framework.git/commitdiff
#6785, #6401: UIDL requests are now handled even though request does not know the...
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Apr 2011 12:08:25 +0000 (12:08 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Apr 2011 12:08:25 +0000 (12:08 +0000)
svn changeset:18158/svn branch:6.5

src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java

index 4cad1cc8e65a7dc6265d2d2b203ad68ad58671e9..152fa81bb5bb7224863bb9ea36ae9defe19912a6 100644 (file)
@@ -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;
     }