branch: externals/websocket
commit 90b9f03da026a5b1a402fc72316a6227ea1a39d5
Author: Ilya Semyonov <[email protected]>
Commit: Ilya Semyonov <[email protected]>
Correctly parse fragmented HTTP header
---
websocket.el | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/websocket.el b/websocket.el
index c42f2ccfe7..4a1cdda3a3 100644
--- a/websocket.el
+++ b/websocket.el
@@ -451,8 +451,8 @@ ERR should be a cons of error symbol and error data."
The only acceptable one to websocket is responce code 101.
A t value will be returned on success, and an error thrown
if not."
- (string-match "HTTP/1.1 \\([[:digit:]]+\\)" output)
- (unless (equal "101" (match-string 1 output))
+ (unless (and (string-match "HTTP/1.1 \\([[:digit:]]+\\)" output)
+ (equal "101" (match-string 1 output)))
(signal 'websocket-received-error-http-response
(string-to-number (match-string 1 output))))
t)
@@ -747,19 +747,21 @@ connection is invalid, the connection will be closed."
(setf (websocket-inflight-input websocket) nil)
;; If we've received the complete header, check to see if we've
;; received the desired handshake.
- (when (and (eq 'connecting (websocket-ready-state websocket))
- (setq header-end-pos (string-match "\r\n\r\n" text))
+ (when (and (eq 'connecting (websocket-ready-state websocket)))
+ (if (and (setq header-end-pos (string-match "\r\n\r\n" text))
(setq start-point (+ 4 header-end-pos)))
- (condition-case err
- (progn
- (websocket-verify-response-code text)
- (websocket-verify-headers websocket text)
- (websocket-process-headers (websocket-url websocket) text))
- (error
- (websocket-close websocket)
- (signal (car err) (cdr err))))
- (setf (websocket-ready-state websocket) 'open)
- (websocket-try-callback 'websocket-on-open 'on-open websocket))
+ (progn
+ (condition-case err
+ (progn
+ (websocket-verify-response-code text)
+ (websocket-verify-headers websocket text)
+ (websocket-process-headers (websocket-url websocket) text))
+ (error
+ (websocket-close websocket)
+ (signal (car err) (cdr err))))
+ (setf (websocket-ready-state websocket) 'open)
+ (websocket-try-callback 'websocket-on-open 'on-open websocket))
+ (setf (websocket-inflight-input websocket) text)))
(when (eq 'open (websocket-ready-state websocket))
(websocket-process-input-on-open-ws
websocket (substring text (or start-point 0))))))