diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-08-30 11:18:16 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-09-02 10:50:53 +0000 |
commit | f7ee8fb1d2c6b6d51e03486968f3bc20e7c44b4d (patch) | |
tree | 5206b6914a36bba4842fee604ad47cb8bd5fd8f5 /WebContent | |
parent | e6af0f0a5a1333d06e18d0149d44231a5f8e654d (diff) | |
download | vaadin-framework-f7ee8fb1d2c6b6d51e03486968f3bc20e7c44b4d.tar.gz vaadin-framework-f7ee8fb1d2c6b6d51e03486968f3bc20e7c44b4d.zip |
Updated _trackMessageSize based on latest upstream version (#12468)
Change-Id: Ie7db27a026d52befe027ed2abb96e62947f8116d
Diffstat (limited to 'WebContent')
-rw-r--r-- | WebContent/VAADIN/jquery.atmosphere.js | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/WebContent/VAADIN/jquery.atmosphere.js b/WebContent/VAADIN/jquery.atmosphere.js index b6f86d428a..520e63d7cb 100644 --- a/WebContent/VAADIN/jquery.atmosphere.js +++ b/WebContent/VAADIN/jquery.atmosphere.js @@ -1199,6 +1199,9 @@ jQuery.atmosphere = function() { * @param response */ function _trackMessageSize(message, request, response) { + if (message.length === 0) + return true; + if (request.trackMessageLength) { // If we have found partial message, prepend them. @@ -1207,36 +1210,29 @@ jQuery.atmosphere = function() { } var messages = []; - var messageLength = 0; var messageStart = message.indexOf(request.messageDelimiter); - while (messageStart != -1) { - messageLength = jQuery.trim(message.substring(messageLength, messageStart)); - message = message.substring(messageStart + request.messageDelimiter.length, message.length); - - // Stop search if there is not enough characters remaining (wait for next part to arrive) - if (message.length == 0 || message.length < messageLength) break; - - // Find start of a possibly existing subsequent message from the remaining data - messageStart = message.substring(messageLength).indexOf(request.messageDelimiter); - - // Store the completely received message - messages.push(message.substring(0, messageLength)); - } - - if (messages.length == 0 || (message.length != 0 && messageLength != message.length)){ - if (messageStart == -1) { - // http://dev.vaadin.com/ticket/12197 - // partialMessage must contain length header of next message - // it starts at the end of the last message - response.partialMessage = message.substring(messageLength); + while (messageStart !== -1) { + var str = jQuery.trim(message.substring(0, messageStart)); + var messageLength = parseInt(str, 10); + if (isNaN(messageLength)) + throw 'message length "' + str + '" is not a number'; + messageStart += request.messageDelimiter.length; + if (messageStart + messageLength > message.length) { + // message not complete, so there is no trailing messageDelimiter + messageStart = -1; } else { - response.partialMessage = messageLength + request.messageDelimiter + message ; + // message complete, so add it + messages.push(message.substring(messageStart, messageStart + messageLength)); + // remove consumed characters + message = message.substring(messageStart + messageLength, message.length); + messageStart = message.indexOf(request.messageDelimiter); } - } else { - response.partialMessage = ""; } - if (messages.length != 0) { + /* keep any remaining data */ + response.partialMessage = message; + + if (messages.length !== 0) { response.responseBody = messages.join(request.messageDelimiter); response.messages = messages; return false; |