Skip to content

Commit ab3889c

Browse files
committed
Update SPEC to fix on-open/on-close guarantees
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 ring-clojure#505.
1 parent 911027b commit ab3889c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

SPEC.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Ring Spec (1.5)
1+
# Ring Spec (1.5.1)
22

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

291291
#### on-open
292292

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

297297
#### on-message
298298

@@ -323,9 +323,11 @@ by the error.
323323

324324
#### on-close
325325

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

330332
### 3.3. Websocket Sockets
331333

0 commit comments

Comments
 (0)