Skip to content

Commit ed29dcc

Browse files
Merge pull request #268721 from vicancy/patch-13
Update reference-cloud-events.md
2 parents fb966c5 + 022e7a6 commit ed29dcc

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

articles/azure-web-pubsub/reference-cloud-events.md

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Or:
3838

3939
`WebHook-Allowed-Origin: xxx.webpubsub.azure.com`
4040

41-
For now, [WebHook-Request-Rate](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#414-webhook-request-rate) and [WebHook-Request-Callback](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#413-webhook-request-callback) are not supported.
41+
For now, [WebHook-Request-Rate](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#414-webhook-request-rate) and [WebHook-Request-Callback](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#413-webhook-request-callback) aren't supported.
4242

4343

4444
## Web PubSub CloudEvents attribute extension
@@ -57,12 +57,12 @@ This extension defines attributes used by Web PubSub for every event it produces
5757
| `connectionId` | `string` | The connectionId is unique for the client connection | |
5858
| `eventName` | `string` | The name of the event without prefix | |
5959
| `subprotocol` | `string` | The subprotocol the client is using if any | |
60-
| `connectionState` | `string` | Defines the state for the connection. You can use the same response header to reset the value of the state. Multiple `connectionState` headers are not allowed. Do base64 encode the string value if it contains complex characters inside, for example, you can `base64(jsonString)` to pass complex object using this attribute.| |
61-
| `signature` | `string` | The signature for the upstream webhook to validate if the incoming request is from the expected origin. The service calculates the value using both primary access key and secondary access key as the HMAC key: `Hex_encoded(HMAC_SHA256(accessKey, connectionId))`. The upstream should check if the request is valid before processing it. | |
60+
| `connectionState` | `string` | Defines the state for the connection. You can use the same response header to reset the value of the state. Multiple `connectionState` headers aren't allowed. Do base64 encode the string value if it contains complex characters inside, for example, `base64(jsonString)` to pass complex object using this attribute.| |
61+
| `signature` | `string` | The signature for the upstream webhook to validate if the incoming request is from the expected origin. The service calculates the value using both primary access key and secondary access key as the `HMAC` key: `Hex_encoded(HMAC_SHA256(accessKey, connectionId))`. The upstream should check if the request is valid before processing it. | |
6262

6363
## Events
6464

65-
There are two types of events, one is *blocking* events that the service waits for the response of the event to continue. One is *unblocking* events that the service doesn't wait for the response of such event before processing the next message.
65+
There are two types of events. One is *blocking* events that the service waits for the response of the event to continue. One is *unblocking* events that the service doesn't wait for the response of such event before processing the next message.
6666

6767
- Blocking events
6868
- [System `connect` event](#connect)
@@ -111,11 +111,29 @@ ce-eventName: connect
111111
```
112112

113113
#### Success response format:
114+
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
115+
114116
* Status code:
115117
* `204`: Success, with no content.
116118
* `200`: Success, the content SHOULD be a JSON format, with following properties allowed:
117-
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Please note that only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
118-
*
119+
* `subprotocols`
120+
121+
The `connect` event forwards the subprotocol and authentication information to Upstream from the client. Web PubSub service uses the status code to determine if the request will be upgraded to WebSocket protocol.
122+
123+
If the request contains the `subprotocols` property, the server should return one subprotocol it supports. If the server doesn't want to use any subprotocols, it should **not** send the `subprotocol` property in response. [Sending a blank header is invalid](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Subprotocols).
124+
125+
* `userId`: `{auth-ed user ID}`
126+
127+
As the service allows anonymous connections, it's the `connect` event's responsibility to tell the service the user ID of the client connection. The service reads the user ID from the response payload `userId` if it exists. The connection is dropped if the user ID can't be read from the request claims nor the `connect` event's response payload.
128+
129+
* `groups`: `{groups to join}`
130+
131+
The property provides a convenient way for user to add this connection to one or multiple groups. In this way, there's no need to have another call to add this connection to some group.
132+
133+
* `roles`: `{roles the client has}`
134+
135+
The property provides a way for the upstream Webhook to authorize the client. There are different roles to grant initial permissions for PubSub WebSocket clients. Details about the permissions are described in [Client permissions](./concept-client-protocols.md#permissions).
136+
119137
```HTTP
120138
HTTP/1.1 200 OK
121139
ce-connectionState: eyJrZXkiOiJhIn0=
@@ -129,26 +147,6 @@ ce-connectionState: eyJrZXkiOiJhIn0=
129147
130148
```
131149

132-
* `subprotocols`
133-
134-
The `connect` event forwards the subprotocol and authentication information to Upstream from the client. Web PubSub service uses the status code to determine if the request will be upgraded to WebSocket protocol.
135-
136-
If the request contains the `subprotocols` property, the server should return one subprotocol it supports. If the server doesn't want to use any subprotocols, it should **not** send the `subprotocol` property in response. [Sending a blank header is invalid](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Subprotocols).
137-
138-
* `userId`: `{auth-ed user ID}`
139-
140-
As the service allows anonymous connections, it's the `connect` event's responsibility to tell the service the user ID of the client connection. The service will read the user ID from the response payload `userId` if it exists. The connection will be dropped if the user ID cannot be read from the request claims nor the `connect` event's response payload.
141-
142-
<a name="connect_response_header_group"></a>
143-
144-
* `groups`: `{groups to join}`
145-
146-
The property provides a convenient way for user to add this connection to one or multiple groups. In this way, there's no need to have another call to add this connection to some group.
147-
148-
* `roles`: `{roles the client has}`
149-
150-
The property provides a way for the upstream Webhook to authorize the client. There are different roles to grant initial permissions for PubSub WebSocket clients. Details about the permissions are described in [Client permissions](./concept-client-protocols.md#permissions).
151-
152150
#### Error response format:
153151

154152
* `4xx`: Error, the response from Upstream will be returned as the response for the client request.
@@ -184,7 +182,7 @@ ce-signature: sha256={connection-id-hash-primary},sha256={connection-id-hash-sec
184182
ce-userId: {userId}
185183
ce-connectionId: {connectionId}
186184
ce-hub: {hub}
187-
ce-eventName: connect
185+
ce-eventName: connected
188186
ce-subprotocol: abc
189187
ce-connectionState: eyJrZXkiOiJhIn0=
190188
@@ -196,7 +194,7 @@ ce-connectionState: eyJrZXkiOiJhIn0=
196194

197195
`2xx`: success response.
198196

199-
`connected` is an asynchronous event, when the response status code is not success, the service logs an error.
197+
`connected` is an asynchronous event, when the response status code isn't success, the service logs an error.
200198

201199
```HTTP
202200
HTTP/1.1 200 OK
@@ -227,7 +225,7 @@ ce-signature: sha256={connection-id-hash-primary},sha256={connection-id-hash-sec
227225
ce-userId: {userId}
228226
ce-connectionId: {connectionId}
229227
ce-hub: {hub}
230-
ce-eventName: disconnect
228+
ce-eventName: disconnected
231229
ce-subprotocol: abc
232230
ce-connectionState: eyJrZXkiOiJhIn0=
233231
@@ -246,7 +244,7 @@ ce-connectionState: eyJrZXkiOiJhIn0=
246244

247245
`2xx`: success response.
248246

249-
`disconnected` is an asynchronous event, when the response status code is not success, the service logs an error.
247+
`disconnected` is an asynchronous event, when the response status code isn't success, the service logs an error.
250248

251249
```HTTP
252250
HTTP/1.1 200 OK
@@ -293,7 +291,7 @@ UserPayload
293291
* `200`: Success, the format of the `UserResponsePayload` depends on the `Content-Type` of the response.
294292
* `Content-Type`: `application/octet-stream` for binary frame; `text/plain` for text frame;
295293
* Header `Content-Type`: `application/octet-stream` for binary frame; `text/plain` for text frame;
296-
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Please note that only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store complex state for the connection.
294+
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store complex state for the connection.
297295

298296
When the `Content-Type` is `application/octet-stream`, the service sends `UserResponsePayload` to the client using `binary` WebSocket frame. When the `Content-Type` is `text/plain`, the service sends `UserResponsePayload` to the client using `text` WebSocket frame.
299297

@@ -307,7 +305,7 @@ UserResponsePayload
307305
```
308306

309307
#### Error response format
310-
When the status code is not success, it is considered to be error response. The connection would be **dropped** if the `message` response status code is not success.
308+
When the status code isn't success, it's considered to be error response. The connection would be **dropped** if the `message` response status code isn't success.
311309

312310
### User custom event `{custom_event}` for PubSub WebSocket clients
313311
<a name="custom_event"></a>
@@ -434,7 +432,7 @@ UserResponsePayload
434432
* Status code
435433
* `204`: Success, with no content.
436434
* `200`: Success, data sending to the PubSub WebSocket client depends on the `Content-Type`;
437-
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Please note that only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
435+
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
438436
* When Header `Content-Type` is `application/octet-stream`, the service sends `UserResponsePayload` back to the client using `dataType` as `binary` with payload base64 encoded. A sample response:
439437
```json
440438
{
@@ -449,7 +447,7 @@ UserResponsePayload
449447

450448

451449
#### Error response format
452-
When the status code is not success, it is considered to be error response. The connection would be **dropped** if the `{custom_event}` response status code is not success.
450+
When the status code isn't success, it's considered to be error response. The connection would be **dropped** if the `{custom_event}` response status code isn't success.
453451

454452
## Next steps
455453

0 commit comments

Comments
 (0)