emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 113/119: Fix WebSocket varint length encoding


From: Eric Schulte
Subject: [elpa] 113/119: Fix WebSocket varint length encoding
Date: Mon, 10 Mar 2014 16:57:57 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit ba2c6429967059d9bc6cc505dbe8db3a947a28eb
Author: Russell Cagle <address@hidden>
Date:   Sun Feb 23 11:30:03 2014 -0500

    Fix WebSocket varint length encoding
---
 web-server-test.el |    9 +++++++++
 web-server.el      |   28 ++++++++++++++--------------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/web-server-test.el b/web-server-test.el
index 0af26e9..9d89ef3 100644
--- a/web-server-test.el
+++ b/web-server-test.el
@@ -249,6 +249,15 @@ Content-Type: application/octet-stream
   (should (string= (ws-web-socket-handshake "dGhlIHNhbXBsZSBub25jZQ==")
                    "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")))
 
+(ert-deftest ws/web-socket-frame ()
+  "Test WebSocket frame encoding for the different varint payload lengths:
+   0-125, 126-64k, 64k-2^64."
+  (should (string= (ws-web-socket-frame "short") "\201short"))
+  (should (string= (substring (ws-web-socket-frame (make-string 126 ?a))
+                              0 5) "\201~~a"))
+  (should (string= (substring (ws-web-socket-frame (make-string 65536 ?a))
+                              0 11) "\201a")))
+
 (ert-deftest ws/simple-chunked ()
   "Test a simple server using chunked transfer encoding."
   (ws-test-with
diff --git a/web-server.el b/web-server.el
index 04813b7..3148f41 100644
--- a/web-server.el
+++ b/web-server.el
@@ -497,20 +497,20 @@ See RFC6455."
     (concat
      (cond
       ((< len 126) (unibyte-string (logior (lsh fin 7) opcode) len))
-      ((= len 126) (unibyte-string (logior (lsh fin 7) opcode) 126
-                                   ;; extended 16-bit length
-                                   (logand (lsh len -8) 255)
-                                   (logand      len     255)))
-      ((> len 126) (unibyte-string (logior (lsh fin 7) opcode) 127
-                                   ;; more extended 64-bit length
-                                   (logand (lsh len -56) 255)
-                                   (logand (lsh len -48) 255)
-                                   (logand (lsh len -40) 255)
-                                   (logand (lsh len -32) 255)
-                                   (logand (lsh len -24) 255)
-                                   (logand (lsh len -16) 255)
-                                   (logand (lsh len -8)  255)
-                                   (logand      len      255))))
+      ((< len 65536) (unibyte-string (logior (lsh fin 7) opcode) 126
+                                     ;; extended 16-bit length
+                                     (logand (lsh len -8) 255)
+                                     (logand      len     255)))
+      (t (unibyte-string (logior (lsh fin 7) opcode) 127
+                         ;; more extended 64-bit length
+                         (logand (lsh len -56) 255)
+                         (logand (lsh len -48) 255)
+                         (logand (lsh len -40) 255)
+                         (logand (lsh len -32) 255)
+                         (logand (lsh len -24) 255)
+                         (logand (lsh len -16) 255)
+                         (logand (lsh len -8)  255)
+                         (logand      len      255))))
      string)))
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]