You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/SignalR/docs/specs/TransportProtocols.md
+60-6Lines changed: 60 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -12,19 +12,65 @@ A transport is required to have the following attributes:
12
12
13
13
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.
14
14
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.
16
16
17
17
**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.
18
18
19
19
## `POST [endpoint-base]/negotiate` request
20
20
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.
22
22
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.
24
28
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:
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:
@@ -45,10 +91,14 @@ The `POST [endpoint-base]/negotiate` request is used to establish a connection b
45
91
The payload returned from this endpoint provides the following data:
46
92
47
93
* 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.
48
95
* 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`)
49
96
97
+
### All versions
98
+
99
+
There are two other possible negotiation responses:
50
100
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.
52
102
53
103
```json
54
104
{
@@ -63,7 +113,7 @@ The `POST [endpoint-base]/negotiate` request is used to establish a connection b
63
113
* The `accessToken` which is an optional bearer token for accessing the specified url.
64
114
65
115
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.
67
117
68
118
```json
69
119
{
@@ -136,10 +186,14 @@ Long Polling requires that the client poll the server for new messages. Unlike t
136
186
137
187
A Poll is established by sending an HTTP GET request to `[endpoint-base]` with the following query string parameters
138
188
189
+
#### Version 1
190
+
*`id` (Required) - The Connection Token of the destination connection.
191
+
192
+
#### Version 0
139
193
*`id` (Required) - The Connection ID of the destination connection.
140
194
141
195
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.
142
196
143
197
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.
144
198
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