Skip to content

Commit 68dcbe3

Browse files
mikaelm12BrennanConroy
authored andcommitted
Update SignalR transport protocol spec (#13916)
1 parent b44e9c6 commit 68dcbe3

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

src/SignalR/docs/specs/TransportProtocols.md

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,65 @@ A transport is required to have the following attributes:
1212

1313
The only transport which fully implements the duplex requirement is WebSockets, the others are "half-transports" which implement one end of the duplex connection. They are used in combination to achieve a duplex connection.
1414

15-
Throughout this document, the term `[endpoint-base]` is used to refer to the route assigned to a particular end point. The term `[connection-id]` is used to refer to the connection ID provided by the `POST [endpoint-base]/negotiate` request.
15+
Throughout this document, the term `[endpoint-base]` is used to refer to the route assigned to a particular end point. The terms `connection-id` and `connectionToken` are used to refer to the connection ID and connection token provided by the `POST [endpoint-base]/negotiate` request.
1616

1717
**NOTE on errors:** In all error cases, by default, the detailed exception message is **never** provided; a short description string may be provided. However, an application developer may elect to allow detailed exception messages to be emitted, which should only be used in the `Development` environment. Unexpected errors are communicated by HTTP `500 Server Error` status codes or WebSockets non-`1000 Normal Closure` close frames; in these cases the connection should be considered to be terminated.
1818

1919
## `POST [endpoint-base]/negotiate` request
2020

21-
The `POST [endpoint-base]/negotiate` request is used to establish a connection between the client and the server. The content type of the response is `application/json`. The response to the `POST [endpoint-base]/negotiate` request contains one of three types of responses:
21+
The `POST [endpoint-base]/negotiate` request is used to establish a connection between the client and the server.
2222

23-
1. A response that contains the `connectionId` which will be used to identify the connection on the server and the list of the transports supported by the server.
23+
In the POST request the client sends a query string parameter with the key "negotiateVersion" and the value as the negotiate protocol version it would like to use. If the query string is omitted, the server treats the version as zero. The server will include a "negotiateVersion" property in the json response that says which version it will be using. The version is chosen as described below:
24+
* If the servers minimum supported protocol version is greater than the version requested by the client it will send an error response and close the connection
25+
* If the server supports the request version it will respond with the requested version
26+
* If the requested version is greater than the servers largest supported version the server will respond with its largest supported version
27+
The client may close the connection if the "negotiateVersion" in the response is not acceptable.
2428

29+
The content type of the response is `application/json` and is a JSON payload containing properties to assist the client in establishing a persistent connection. Extra JSON properties that the client does not know about should be ignored. This allows for future additions without breaking older clients.
30+
31+
### Version 1
32+
33+
When the server and client agree on version 1 the server response will include a "connectionToken" property in addition to the "connectionId" property. The value of the "connectionToken" property will be used in the "id" query string for the HTTP requests described below, this value should be kept secret.
34+
35+
A successful negotiate response will look similar to the following payload:
2536
```json
2637
{
38+
"connectionToken":"05265228-1e2c-46c5-82a1-6a5bcc3f0143",
2739
"connectionId":"807809a5-31bf-470d-9e23-afaee35d8a0d",
40+
"negotiateVersion":1,
41+
"availableTransports":[
42+
{
43+
"transport": "WebSockets",
44+
"transferFormats": [ "Text", "Binary" ]
45+
},
46+
{
47+
"transport": "ServerSentEvents",
48+
"transferFormats": [ "Text" ]
49+
},
50+
{
51+
"transport": "LongPolling",
52+
"transferFormats": [ "Text", "Binary" ]
53+
}
54+
]
55+
}
56+
```
57+
58+
The payload returned from this endpoint provides the following data:
59+
60+
* The `connectionToken` which is **required** by the Long Polling and Server-Sent Events transports (in order to correlate sends and receives).
61+
* The `connectionId` which is the id by which other clients can refer to it.
62+
* The `negotiateVersion` which is the negotiation protocol version being used between the server and client.
63+
* The `availableTransports` list which describes the transports the server supports. For each transport, the name of the transport (`transport`) is listed, as is a list of "transfer formats" supported by the transport (`transferFormats`)
64+
65+
### Version 0
66+
67+
When the server and client agree on version 0 the server response will include a "connectionId" property that is used in the "id" query string for the HTTP requests described below.
68+
69+
A successful negotiate response will look similar to the following payload:
70+
```json
71+
{
72+
"connectionId":"807809a5-31bf-470d-9e23-afaee35d8a0d",
73+
"negotiateVersion":0,
2874
"availableTransports":[
2975
{
3076
"transport": "WebSockets",
@@ -45,10 +91,14 @@ The `POST [endpoint-base]/negotiate` request is used to establish a connection b
4591
The payload returned from this endpoint provides the following data:
4692

4793
* The `connectionId` which is **required** by the Long Polling and Server-Sent Events transports (in order to correlate sends and receives).
94+
* The `negotiateVersion` which is the negotiation protocol version being used between the server and client.
4895
* The `availableTransports` list which describes the transports the server supports. For each transport, the name of the transport (`transport`) is listed, as is a list of "transfer formats" supported by the transport (`transferFormats`)
4996

97+
### All versions
98+
99+
There are two other possible negotiation responses:
50100

51-
2. A redirect response which tells the client which URL and optionally access token to use as a result.
101+
1. A redirect response which tells the client which URL and optionally access token to use as a result.
52102

53103
```json
54104
{
@@ -63,7 +113,7 @@ The `POST [endpoint-base]/negotiate` request is used to establish a connection b
63113
* The `accessToken` which is an optional bearer token for accessing the specified url.
64114

65115

66-
3. A response that contains an `error` which should stop the connection attempt.
116+
1. A response that contains an `error` which should stop the connection attempt.
67117

68118
```json
69119
{
@@ -136,10 +186,14 @@ Long Polling requires that the client poll the server for new messages. Unlike t
136186

137187
A Poll is established by sending an HTTP GET request to `[endpoint-base]` with the following query string parameters
138188

189+
#### Version 1
190+
* `id` (Required) - The Connection Token of the destination connection.
191+
192+
#### Version 0
139193
* `id` (Required) - The Connection ID of the destination connection.
140194

141195
When data is available, the server responds with a body in one of the two formats below (depending upon the value of the `Accept` header). The response may be chunked, as per the chunked encoding part of the HTTP spec.
142196

143197
If the `id` parameter is missing, a `400 Bad Request` response is returned. If there is no connection with the ID specified in `id`, a `404 Not Found` response is returned.
144198

145-
When the client has finished with the connection, it can issue a `DELETE` request to `[endpoint-base]` (with the `id` in the querystring) to gracefully terminate the connection. The server will complete the latest poll with `204` to indicate that it has shut down.
199+
When the client has finished with the connection, it can issue a `DELETE` request to `[endpoint-base]` (with the `id` in the query string) to gracefully terminate the connection. The server will complete the latest poll with `204` to indicate that it has shut down.

0 commit comments

Comments
 (0)