Skip to content

Commit 7420d57

Browse files
committed
rename id to token; change handle-frames signature
- rename `id` to `token`: This helps emphasize that it's a secret. - change `handle-frames` signature: for security, don't pass frames from multiple clients to a single call to a single instance. Signed-off-by: Joel Dice <[email protected]>
1 parent 150f0c0 commit 7420d57

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

docs/content/sips/016-inbound-websockets.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ interface inbound-websocket-receive {
121121
// Construct a new handler for the specified request, which the
122122
// client has requested to be upgraded to a WebSocket.
123123
//
124-
// - `id`: a globally unique identifier which may be used to send
125-
// frames to this WebSocket using
124+
// - `token`: a globally unique identifier which may be used to
125+
// send frames to this WebSocket using
126126
// `outgoing-websocket#send-frame`. Note that any application
127-
// may use this `id` to send frames to the WebSocket for as
127+
// may use this `token` to send frames to the WebSocket for as
128128
// long as it is connected, which means it should be treated as
129129
// a secret and shared only with trusted parties.
130130
//
@@ -135,12 +135,11 @@ interface inbound-websocket-receive {
135135
// response to the client. If (and only if) the response has a
136136
// status code of 101, then the connection will be upgraded to a
137137
// WebSocket.
138-
handle-new: func(id: string, request: incoming-request, response-out: response-outparam);
138+
handle-new: func(token: string, request: incoming-request, response-out: response-outparam);
139139
140140
// Handle the most recent frames received for the specified
141-
// WebSockets. `frames` consists of a mapping from WebSocket ids
142-
// to ordered lists of frames.
143-
handle-frames: func(frames: list<tuple<string, list<received-frame>>);
141+
// WebSocket.
142+
handle-frames: func(token: string, frames: list<received-frame>);
144143
}
145144
146145
interface inbound-websocket-send {
@@ -151,7 +150,7 @@ interface inbound-websocket-send {
151150
// This will fail if the WebSocket is no longer open. Otherwise,
152151
// if the frame is an instance of `close`, the connection will
153152
// be closed after sending the frame.
154-
send-frame: func(id: string, frame: frame) -> future-send-frame;
153+
send-frame: func(token: string, frame: frame) -> future-send-frame;
155154
}
156155
157156
world inbound-websocket-handler {
@@ -175,7 +174,7 @@ As frames arrive from the client, Spin will create new instances and pass the fr
175174

176175
If a connection is lost unexpectedly prior to receiving a WebSocket `close` frame from the client, Spin will attempt synthesize such a frame and deliver to the application, giving it an opportunity to clean up associated state. Note, however, there is no guarantee that the app will always receive a `close` frame promptly or at all -- external factors such as network failures or power loss might delay or prevent that, so apps should not rely exclusively on it.
177176

178-
Each open WebSocket will be assigned a unique, opaque ID (e.g. a 128-bit, base-64-encoded, securely-generated random number) which may be used by any component of any type (e.g. `http`, `redis`, or `websocket`) to send frames to the client via `fermyon:spin/inbound-websocket-send#send-frame`. For example, a chat application might use these IDs (or aliases thereof) to route chat messages within a group.
177+
Each open WebSocket will be assigned a unique, opaque token (e.g. a 128-bit, base-64-encoded, securely-generated random number, or perhaps a signed, encrypted auth token) which may be used by any component of any type (e.g. `http`, `redis`, `websocket`, etc.) to send frames to the client via `fermyon:spin/inbound-websocket-send#send-frame`. For example, a chat application might use these tokens (or aliases thereof) to route chat messages within a group.
179178

180179
## Scalability and Reliability
181180

0 commit comments

Comments
 (0)