Browse files

Test for websocket-outer-filter, plus removing some useless code from…

… that function.
  • Loading branch information...
1 parent 33ff92c commit b89e002187ce932e82394023820deb8407842291 @ahyatt committed May 26, 2012
Showing with 25 additions and 2 deletions.
  1. +24 −0 websocket-test.el
  2. +1 −2 websocket.el
View
24 websocket-test.el
@@ -225,3 +225,27 @@
(should (equal sent-frames (list
(make-websocket-frame :opcode 'close
:completep t)))))))
+
+(ert-deftest websocket-outer-filter ()
+ (let* ((fake-ws (make-websocket :conn t :filter t :url t
+ :accept-string t :close-callback t))
+ (processed-frames)
+ (frame1 (make-websocket-frame :opcode 'text :payload "foo" :completep t
+ :length 9))
+ (frame2 (make-websocket-frame :opcode 'text :payload "bar" :completep t
+ :length 9))
+ (websocket-frames
+ (concat
+ (websocket-encode-frame frame1)
+ (websocket-encode-frame frame2))))
+ (flet ((websocket-process-frame (websocket frame)
+ (push frame processed-frames))
+ (websocket-verify-handshake (websocket output) t))
+ (websocket-outer-filter fake-ws "Sec-")
+ (websocket-outer-filter fake-ws "WebSocket-Accept: acceptstring")
+ (websocket-outer-filter fake-ws (concat
+ "\r\n\r\n"
+ (substring websocket-frames 0 2)))
+ (should (websocket-header-read-p fake-ws))
+ (websocket-outer-filter fake-ws (substring websocket-frames 2))
+ (should (equal (list frame2 frame1) processed-frames)))))
View
3 websocket.el
@@ -350,8 +350,7 @@ If the frame is a close, we terminate the connection."
(when (websocket-header-read-p websocket)
(unless start-point (setq start-point 0))
(let ((current-frame))
- (while (and (websocket-header-read-p websocket)
- (setq current-frame (websocket-read-frame
+ (while (and (setq current-frame (websocket-read-frame
(substring text start-point))))
(websocket-process-frame websocket current-frame)
(incf start-point (websocket-frame-length current-frame)))))

0 comments on commit b89e002

Please sign in to comment.