Skip to content

Commit

Permalink
Update SPEC to fix on-open/on-close guarantees
Browse files Browse the repository at this point in the history
Sometimes a HTTP request is upgraded to a WebSocket, but the WebSocket
is not correctly initiated. If the WebSocket is never successfully
opened, then on-open should not be called; similarly, on-close will
only be called if on-open has been, as if a WebSocket has not been
opened, it cannot be closed.

This commit adjusts the SPEC to specify this, updates the SPEC version
to 1.5.1, and fixes #505.
  • Loading branch information
weavejester committed May 9, 2024
1 parent 911027b commit ab3889c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions SPEC.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ring Spec (1.5)
# Ring Spec (1.5.1)

Ring is an abstraction layer for building HTTP server applications in
Clojure.
Expand Down Expand Up @@ -290,9 +290,9 @@ message that has the same data.

#### on-open

Called once when the websocket is first opened. Supplies a `socket`
argument that satisfies `ring.websocket.protools/Socket`, described in
section 3.3.
Called once when the websocket is *successfully* opened. Supplies a
`socket` argument that satisfies `ring.websocket.protools/Socket`,
described in section 3.3.

#### on-message

Expand Down Expand Up @@ -323,9 +323,11 @@ by the error.

#### on-close

Called once when the websocket is closed. Guaranteed to be called, even
if an error occurs, so may be used for finalizing/cleanup logic. Takes
an integer `code` and a string `reason` as arguments.
Called once when the websocket is closed, either via a valid close
frame or by an abnormal disconnect of the underlying TCP connection.
Guaranteed to be called if and only if `on-open` was called, so may be
used for finalizing/cleanup logic. Takes an integer `code` and a string
`reason` as arguments.

### 3.3. Websocket Sockets

Expand Down

0 comments on commit ab3889c

Please sign in to comment.