mod_websocket: Fix length calculation
authorFlorian Zeitz <florob@babelmonkeys.de>
Thu, 30 May 2013 22:48:19 +0200
changeset 1025 b56a9aa171b3
parent 1024 d7655e634c30
child 1026 e254cf49e14d
mod_websocket: Fix length calculation
mod_websocket/mod_websocket.lua
--- a/mod_websocket/mod_websocket.lua	Wed May 29 11:37:42 2013 +0200
+++ b/mod_websocket/mod_websocket.lua	Thu May 30 22:48:19 2013 +0200
@@ -107,10 +107,13 @@
 		result = result .. string.char(126);
 		result = result .. string.char(rshift(length, 8)) .. string.char(length%0x100);
 	else -- 8-byte length
+		local length_bytes = {};
 		result = result .. string.char(127);
-		for i = 7, 0, -1 do
-			result = result .. string.char(rshift(length, 8*i) % 0x100);
+		for i = 8, 1, -1 do
+			length_bytes[i] = string.char(length % 0x100);
+			length = rshift(length, 8);
 		end
+		result = result .. table.concat(length_bytes, "");
 	end
 
 	result = result .. data;