Skip to content

Commit

Permalink
Add a function to calculate the accept header expected.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyatt committed May 7, 2012
1 parent 763cb60 commit b5bbce1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions websocket-test.el
Expand Up @@ -76,7 +76,14 @@
(websocket-test-get-filtered-response
'("HTTP 1.1" "\0foo\377")))))

(ert-deftest websocket-calculate-accept ()
;; This example comes straight from RFC 6455
(should
(equal "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="
(websocket-calculate-accept "dGhlIHNhbXBsZSBub25jZQ=="))))

(ert-run-tests-interactively 'websocket-genbytes-length)
(ert-run-tests-interactively 'websocket-filter-basic)
(ert-run-tests-interactively 'websocket-filter-inflight-packets)
(ert-run-tests-interactively 'websocket-filter-first-response)
(ert-run-tests-interactively 'websocket-calculate-accept)
10 changes: 10 additions & 0 deletions websocket.el
Expand Up @@ -41,6 +41,10 @@
The buffer is ` *websocket URL debug*' where URL is the
URL of the connection.")

(defconst websocket-guid "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
"The websocket GUID as defined in RFC 6455. Do not change
unless the RFC changes.")

(defun websocket-genbytes ()
"Generate bytes used at the end of the handshake."
(let ((s " "))
Expand Down Expand Up @@ -71,6 +75,12 @@ URL of the connection.")
max-num-str)))
(cons max-num-str num)))

(defun websocket-calculate-accept (key)
"Calculate the expect value of the accept header.
This is based on the KEY from the Sec-WebSocket-Key header."
(base64-encode-string
(sha1 (concat key websocket-guid) nil nil t)))

(defun websocket-open (url filter &optional close-callback)
"Open a websocket connection to URL.
Websocket packets are sent as the only argument to FILTER, and if
Expand Down

0 comments on commit b5bbce1

Please sign in to comment.