[Top][All Lists]

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

[elpa] externals/websocket 6fa9830 07/16: Version 1.6, mostly fixes for

From: Stefan Monnier
Subject: [elpa] externals/websocket 6fa9830 07/16: Version 1.6, mostly fixes for fragmented headers.
Date: Fri, 27 Nov 2020 17:47:19 -0500 (EST)

branch: externals/websocket
commit 6fa9830bc19d13bf1e925ea63fde0475a64a6975
Author: Andrew Hyatt <ahyatt@gmail.com>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Version 1.6, mostly fixes for fragmented headers.
    * websocket.el (websocket-verify-response-code, websocket-outer-filter):
      Fix handling of fragmented headers.
    * websocket.el (websocket-server): Accept host for listening on.
    * websocket-functional-test.el: Stop stopping the listener process on
 websocket-functional-test.el |  8 +++++++-
 websocket.el                 | 39 ++++++++++++++++++++++++---------------
 2 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/websocket-functional-test.el b/websocket-functional-test.el
index 6a9481f..1bbd190 100644
--- a/websocket-functional-test.el
+++ b/websocket-functional-test.el
@@ -79,7 +79,10 @@
 (websocket-close wstest-ws)
 (assert (null (websocket-openp wstest-ws)))
-(stop-process wstest-server-proc)
+(if (not (eq system-type 'windows-nt))
+    ; Windows doesn't have support for the SIGSTP signal, so we'll just kill
+    ; the process.
+    (stop-process wstest-server-proc))
 (kill-process wstest-server-proc)
 ;; Make sure the processes are closed.  This happens asynchronously,
@@ -93,6 +96,8 @@
 (when (>= (string-to-int (substring emacs-version 0 2)) 24)
   (message "Testing with wss://echo.websocket.org")
+  (when (eq system-type 'windows-nt)
+    (message "Windows users must have gnutls DLLs in the emacs bin 
   (setq wstest-ws
@@ -123,6 +128,7 @@
 (setq wstest-closed nil)
 (setq server-conn (websocket-server
+                   :host 'local
                    :on-message (lambda (ws frame)
                                  (message "Server received text!")
                                  (websocket-send-text ws
diff --git a/websocket.el b/websocket.el
index 1b0b294..8cd51ae 100644
--- a/websocket.el
+++ b/websocket.el
@@ -4,7 +4,7 @@
 ;; Author: Andrew Hyatt <ahyatt@gmail.com>
 ;; Keywords: Communication, Websocket, Server
-;; Version: 1.5
+;; Version: 1.6
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License as
@@ -450,10 +450,11 @@ 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 (string-match "^HTTP/1.1 \\([[:digit:]]+\\)" output)
+    (signal 'websocket-invalid-header "Invalid HTTP status line"))
   (unless (equal "101" (match-string 1 output))
-       (signal 'websocket-received-error-http-response
-               (string-to-number (match-string 1 output))))
+    (signal 'websocket-received-error-http-response
+           (string-to-number (match-string 1 output))))
 (defun websocket-parse-repeated-field (output field)
@@ -746,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
-            (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))
+            (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 (substring text (or start-point 0))))))
@@ -820,6 +823,11 @@ of populating the list of server extensions to WEBSOCKET."
 (defun* websocket-server (port &rest plist)
   "Open a websocket server on PORT.
+If the plist contains a `:host' HOST pair, this value will be
+used to configure the addresses the socket listens on. The symbol
+`local' specifies the local host. If unspecified or nil, the
+socket will listen on all addresses.
 This also takes a plist of callbacks: `:on-open', `:on-message',
 `:on-close' and `:on-error', which operate exactly as documented
 in the websocket client function `websocket-open'.  Returns the
@@ -833,6 +841,7 @@ connection, which should be kept in order to pass to
                 :log 'websocket-server-accept
                 :filter-multibyte nil
                 :plist plist
+                :host (plist-get plist :host)
                 :service port)))

reply via email to

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