[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) "\201 a")))
+
(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)))
- [elpa] 103/119: set Content-length when serving files, (continued)
- [elpa] 103/119: set Content-length when serving files, Eric Schulte, 2014/03/10
- [elpa] 95/119: better ws-send-directory-list, Eric Schulte, 2014/03/10
- [elpa] 106/119: TODO Content and Transfer encodings, Eric Schulte, 2014/03/10
- [elpa] 104/119: tweak notes, Eric Schulte, 2014/03/10
- [elpa] 108/119: test chunked/gzipped transfer/content encodings, Eric Schulte, 2014/03/10
- [elpa] 100/119: manual application of x-gzip content encoding, Eric Schulte, 2014/03/10
- [elpa] 101/119: manual application of chunked transfer encoding, Eric Schulte, 2014/03/10
- [elpa] 107/119: support for content and transfer encodings, Eric Schulte, 2014/03/10
- [elpa] 109/119: doc for new content/transfer encoding helpers, Eric Schulte, 2014/03/10
- [elpa] 110/119: automatically generate dir file w/install-info, Eric Schulte, 2014/03/10
- [elpa] 113/119: Fix WebSocket varint length encoding,
Eric Schulte <=
- [elpa] 117/119: adding .elpaignore to keep extra file from package, Eric Schulte, 2014/03/10
- [elpa] 115/119: gnu elpa wants a "Maintainer:" pseudo-header, Eric Schulte, 2014/03/10
- [elpa] 114/119: dangerous example; web-socket comint shell buffer, Eric Schulte, 2014/03/10
- [elpa] 105/119: mention `make check' in README, Eric Schulte, 2014/03/10
- [elpa] 116/119: assign copyright to FSF, Eric Schulte, 2014/03/10
- [elpa] 111/119: Emacs packaging support with "make package", Eric Schulte, 2014/03/10
- [elpa] 118/119: README and install instructions mention GNU ELPA, Eric Schulte, 2014/03/10
- [elpa] 112/119: add/use standard source headers, Eric Schulte, 2014/03/10
- [elpa] 119/119: Add 'packages/web-server/' from commit 'd0b6ae9df6014db2195da0081dc97cc8246f1fda', Eric Schulte, 2014/03/10