[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/websocket 8d540d4 13/16: websocket: Version 1.9, custom
From: |
Stefan Monnier |
Subject: |
[elpa] externals/websocket 8d540d4 13/16: websocket: Version 1.9, custom header support. |
Date: |
Fri, 27 Nov 2020 17:47:20 -0500 (EST) |
branch: externals/websocket
commit 8d540d400cdc48335666b82398f1aadece3c5e49
Author: Andrew Hyatt <ahyatt@gmail.com>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
websocket: Version 1.9, custom header support.
* packages/websocket/websocket.el (websocket-open): Add new keyword arg,
:custom-header-alist.
* packages/websocket/websocket.el (websocket-create-headers): Create custom
headers if passed in.
* packages/websocket/websocket-functional-test.el: Add additional wait to
help
avoid flaky failures.
---
websocket-functional-test.el | 1 +
websocket.el | 32 +++++++++++++++++++++++---------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/websocket-functional-test.el b/websocket-functional-test.el
index 80eb004..cc9ac70 100644
--- a/websocket-functional-test.el
+++ b/websocket-functional-test.el
@@ -116,6 +116,7 @@
wstest-msgs nil)
(sleep-for 0.3)
(assert (websocket-openp wstest-ws))
+ (sleep-for 0.6)
(assert (eq 'open (websocket-ready-state wstest-ws)))
(assert (null wstest-msgs))
(websocket-send-text wstest-ws "Hi!")
diff --git a/websocket.el b/websocket.el
index 0533fb3..6d8d954 100644
--- a/websocket.el
+++ b/websocket.el
@@ -4,7 +4,7 @@
;; Author: Andrew Hyatt <ahyatt@gmail.com>
;; Keywords: Communication, Websocket, Server
-;; Version: 1.8
+;; Version: 1.9
;; Package-Requires: ((cl-lib "0.5"))
;;
;; This program is free software; you can redistribute it and/or
@@ -99,7 +99,7 @@ same for the protocols."
accept-string
(inflight-input nil))
-(defvar websocket-version "1.5"
+(defvar websocket-version "1.9"
"Version numbers of this version of websocket.el.")
(defvar websocket-debug nil
@@ -606,7 +606,8 @@ connecting or open."
(cl-defun websocket-open (url &key protocols extensions (on-open 'identity)
(on-message (lambda (_w _f))) (on-close 'identity)
- (on-error 'websocket-default-error-handler))
+ (on-error 'websocket-default-error-handler)
+ (nowait nil) (custom-header-alist nil))
"Open a websocket connection to URL, returning the `websocket' struct.
The PROTOCOL argument is optional, and setting it will declare to
the server that this client supports the protocols in the list
@@ -676,6 +677,14 @@ describing the invalid header received from the server.
`websocket-unparseable-frame': Data in the error is a string
describing the problem with the frame.
+
+`nowait': If NOWAIT is true, return without waiting for the
+connection to complete.
+
+`custom-headers-alist': An alist of custom headers to pass to the
+server. The car is the header name, the cdr is the header value.
+These are different from the extensions because it is not related
+to the websocket protocol.
"
(let* ((name (format "websocket to %s" url))
(url-struct (url-generic-parse-url url))
@@ -691,9 +700,9 @@ describing the problem with the frame.
(host (url-host url-struct)))
(if (eq type 'plain)
(make-network-process :name name :buffer nil :host
host
- :service port :nowait nil)
+ :service port :nowait nowait)
(condition-case-unless-debug nil
- (open-network-stream name nil host port :type
type :nowait nil)
+ (open-network-stream name nil host port :type
type :nowait nowait)
(wrong-number-of-arguments
(signal 'websocket-wss-needs-emacs-24 "wss")))))
(signal 'websocket-unsupported-protocol (url-type
url-struct))))
@@ -731,7 +740,8 @@ describing the problem with the frame.
(websocket-debug websocket "Sending handshake, key: %s, acceptance: %s"
key (websocket-accept-string websocket))
(process-send-string conn
- (websocket-create-headers url key protocols
extensions))
+ (websocket-create-headers
+ url key protocols extensions custom-header-alist))
(websocket-debug websocket "Websocket opened")
websocket))
@@ -899,9 +909,10 @@ connection, which should be kept in order to pass to
(not (eq 'closed (websocket-ready-state websocket))))
(websocket-try-callback 'websocket-on-close 'on-close
websocket)))))))
-(defun websocket-create-headers (url key protocol extensions)
- "Create connections headers for the given URL, KEY, PROTOCOL and EXTENSIONS.
-These are defined as in `websocket-open'."
+(defun websocket-create-headers (url key protocol extensions
custom-headers-alist)
+ "Create connections headers for the given URL, KEY, PROTOCOL, and EXTENSIONS.
+Additionally, the CUSTOM-HEADERS-ALIST is passed from the client.
+All these parameters are defined as in `websocket-open'."
(let* ((parsed-url (url-generic-parse-url url))
(host-port (if (url-port-if-non-default parsed-url)
(format "%s:%s" (url-host parsed-url) (url-port
parsed-url))
@@ -932,6 +943,9 @@ These are defined as in `websocket-open'."
(mapconcat 'identity (cdr ext) "; "))))
extensions ", ")))
(when cookie-header cookie-header)
+ (concat (mapconcat (lambda (cons) (format "%s: %s" (car
cons) (cdr cons)))
+ custom-headers-alist "\r\n")
+ (when custom-headers-alist "\r\n"))
"\r\n")
host-port
key
- [elpa] externals/websocket 45d421d 09/16: Fix some quoting problems in doc strings, (continued)
- [elpa] externals/websocket 45d421d 09/16: Fix some quoting problems in doc strings, Stefan Monnier, 2020/11/27
- [elpa] externals/websocket e008e03 02/16: websocket.el: Set version to 1.2, after last set of server fixes., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket 2aad0b2 03/16: Upgrade to version 1.3., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket 50d62ac 05/16: Add ability to handle cookies., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket 6872e74 06/16: Fix maintainer address, Stefan Monnier, 2020/11/27
- [elpa] externals/websocket 6fa9830 07/16: Version 1.6, mostly fixes for fragmented headers., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket 3b21915 10/16: Update to emacs-websocket version 1.8., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket ba4334b 11/16: Remove use of string-make-unibyte and other cleanups., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket 65b3e1c 12/16: Port websocket to bleeding-edge 32-bit Emacs, Stefan Monnier, 2020/11/27
- [elpa] externals/websocket bc57ded 15/16: Upgrade websocket library to version 1.11.1., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket 8d540d4 13/16: websocket: Version 1.9, custom header support.,
Stefan Monnier <=
- [elpa] externals/websocket c4d8d58 14/16: Fix confusing documentation string in websocket library., Stefan Monnier, 2020/11/27
- [elpa] externals/websocket f11d03a 16/16: Allow websocket accept header variants., Stefan Monnier, 2020/11/27