The term WebSocket subprotocol refers to an application-level protocol layered on top of a WebSocket connection. This document specifies the WebSocket JMAP subprotocol for carrying JMAP API requests, responses, and optional push notifications through a WebSocket connection. Binary data is handled per
Section 6 of
RFC 8620 (via a separate HTTP connection or stream) or per a future extension to JMAP or this specification.
A JMAP WebSocket connection is authenticated by presenting a user's [
RFC 7235] that initiates the WebSocket handshake. See
Section 8.2 of
RFC 8620 for recommendations regarding the selection of HTTP authentication schemes.
The JMAP WebSocket client and JMAP WebSocket server negotiate the use of the WebSocket JMAP subprotocol during the WebSocket handshake, either via an HTTP/1.1 Upgrade request (see
Section 4 of
RFC 6455) or an HTTP/2 Extended CONNECT request (see
Section 5 of
RFC 8441). The WebSocket JMAP subprotocol is also intended to run over future bindings of HTTP (e.g., HTTP/3) provided that there is a defined mechanism for performing a WebSocket handshake over that binding.
Regardless of the method used for the WebSocket handshake, the client
MUST first perform a TLS handshake on a JMAP
Section 3 having the "wss://" scheme (WebSocket over TLS) in accordance with the requirements of running the particular binding of HTTP over TLS (see [
RFC 2818] and
Section 4.1 of
RFC 6455 for HTTP/1.1 and
Section 9.2 of
RFC 7540 for HTTP/2). If the TLS handshake fails, the client
MUST close the connection. Otherwise, the client
MUST make an [
RFC 7235] on the encrypted connection and
MUST include the value "jmap" in the list of protocols for the "Sec-WebSocket-Protocol" header field.
The reply from the server
MUST also contain a corresponding "Sec-WebSocket-Protocol" header field with a value of "jmap" in order for a JMAP subprotocol connection to be established.
Once the handshake has successfully completed, the WebSocket connection is established and can be used for JMAP API requests, responses, and optional push notifications. Other message types
MUST NOT be transmitted over this connection.
The credentials used for authenticating the HTTP request to initiate the handshake remain in effect for the duration of the WebSocket connection. If the authentication credentials for the user expire, the server can either treat subsequent requests as if they are unauthenticated or close the WebSocket connection. In the latter case, the server
MAY send a Close frame with a status code of 1008 (Policy Violation), as defined in
Section 7.4.1 of
RFC 6455.
Data frame messages in the JMAP subprotocol
MUST be text frames and contain UTF-8 encoded data. The messages
MUST be in the form of a single JMAP Request object (see
Section 3.3 of
RFC 8620), JMAP WebSocketPushEnable object (see
Section 4.3.5.2), or JMAP WebSocketPushDisable object (see
Section 4.3.5.3) when sent from the client to the server, and MUST be in the form of a single JMAP Response object, JSON Problem Details object, or JMAP StateChange object (see Sections
3.4,
3.6.1, and
7.1 of [
RFC 8620], respectively) when sent from the server to the client.
Note that fragmented WebSocket messages (split over multiple text frames)
MUST be coalesced prior to parsing them as JSON objects.
If a client or server receives a binary frame, the endpoint can either ignore the frame or close the WebSocket connection. In the latter case, the endpoint
MAY send a Close frame with a status code of 1003 (Unsupported Data), as defined in
Section 7.4.1 of
RFC 6455.
If a client receives a message that is not in the form of a JSON Problem Details object, a JMAP Response object, or a JMAP StateChange object, the client can either ignore the message or close the WebSocket connection. In the latter case, the endpoint
MAY send a Close frame with a status code of 1007 (Invalid frame payload data), as defined in
Section 7.4.1 of
RFC 6455.
A server
MUST return an appropriate
Section 4.3.4 for any request-level errors (e.g., an invalid JMAP object, an unsupported capability or method call, or exceeding a server request limit).
The specification extends the Request object with two additional arguments when used over a WebSocket:
-
@type: "String"
This MUST be the string "Request".
-
id: "String" (optional)
A client-specified identifier for the request to be echoed back in the response to this request.
JMAP over WebSocket allows the server to process requests out of order. The client-specified identifier is used as a mechanism for the client to correlate requests and responses.
Additionally, the "maxConcurrentRequests" limit in the "capabilities" object (see
Section 2 of
RFC 8620) also applies to requests made on the WebSocket connection. When using the WebSocket JMAP subprotocol over a binding of HTTP that allows multiplexing of requests (e.g., HTTP/2), this limit applies to the sum of requests made on both the JMAP API endpoint and the WebSocket connection.
The specification extends the Response object with two additional arguments when used over a WebSocket:
-
@type: "String"
This MUST be the string "Response".
-
requestId: "String" (optional; MUST be returned if an identifier is included in the request)
The client-specified identifier in the corresponding request.
The specification extends the Problem Details object for request-level errors (see
Section 3.6.1 of
RFC 8620) with two additional arguments when used over a WebSocket:
-
@type: "String"
This MUST be the string "RequestError".
-
requestId: "String" (optional; MUST be returned if given in the request)
The client-specified identifier in the corresponding request.
JMAP-over-WebSocket servers that support push notifications on the WebSocket will advertise a "supportsPush" property with a value of true in the "urn:ietf:params:jmap:websocket" server capabilities object.
All push notifications take the form of a standard StateChange object (see
Section 7.1 of
RFC 8620).
The specification extends the StateChange object with one additional argument when used over a WebSocket:
-
pushState: "String" (optional)
A (preferably short) string that encodes the entire server state visible to the user (not just the objects returned in this call).
The purpose of the "pushState" token is to allow a client to immediately get any changes that occurred while it was disconnected (see Section 4.3.5.2). If the server does not support "pushState" tokens, the client will have to issue a series of "/changes" requests (see Section 5.2 of RFC 8620) upon reconnection to update its state to match that of the server.
A client enables push notifications from the server for the current connection by sending a WebSocketPushEnable object to the server. A WebSocketPushEnable object has the following properties:
-
@type: "String"
This MUST be the string "WebSocketPushEnable".
-
dataTypes: "String[]|null"
A list of data type names (e.g., "Mailbox" or "Email") that the client is interested in. A StateChange notification will only be sent if the data for one of these types changes. Other types are omitted from the TypeState object. If null, changes will be pushed for all supported data types.
-
pushState: "String" (optional)
The last "pushState" token that the client received from the server. Upon receipt of a "pushState" token, the server SHOULD immediately send all changes since that state token.
A client disables push notifications from the server for the current connection by sending a WebSocketPushDisable object to the server. A WebSocketPushDisable object has the following property:
-
@type: "String"
This MUST be the string "WebSocketPushDisable".
The following examples show WebSocket JMAP opening handshakes, a JMAP Core/echo request and response, and a subsequent closing handshake. The examples assume that the JMAP WebSocket URL endpoint has been advertised in the JMAP Session object as having a path of "/jmap/ws/" and that TLS negotiation has already succeeded. Note that folding of header fields is for editorial purposes only.
WebSocket JMAP connection via HTTP/1.1 with push notifications for mail [
RFC 8621] is enabled. This example assumes that the client has cached pushState "aaa" from a previous connection.
[[ From Client ]] [[ From Server ]]
GET /jmap/ws/ HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Authorization: Basic Zm9vOmJhcg==
Sec-WebSocket-Key:
dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Protocol: jmap
Sec-WebSocket-Version: 13
Origin: https://www.example.com
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept:
s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: jmap
[WebSocket connection established]
WS_DATA
{
"@type": "WebSocketPushEnable",
"dataTypes": [ "Mailbox", "Email" ],
"pushState": "aaa"
}
WS_DATA
{
"@type": "StateChange",
"changed": {
"a456": {
"Mailbox": "d35ecb040aab"
}
},
"pushState": "bbb"
}
WS_DATA
{
"@type": "Request",
"id": "R1",
"using": [ "urn:ietf:params:jmap:core" ],
"methodCalls": [
[
"Core/echo", {
"hello": true,
"high": 5
},
"b3ff"
]
]
}
WS_DATA
{
"@type": "Response",
"requestId": "R1",
"methodResponses": [
[
"Core/echo", {
"hello": true,
"high": 5
},
"b3ff"
]
]
}
WS_DATA
The quick brown fox jumps
over the lazy dog.
WS_DATA
{
"@type": "RequestError",
"requestId": null,
"type":
"urn:ietf:params:jmap:error:notJSON",
"status": 400,
"detail":
"The request did not parse as I-JSON."
}
[A new email is received]
WS_DATA
{
"@type": "StateChange",
"changed": {
"a123": {
"Email": "0af7a512ce70"
}
}
"pushState": "ccc"
}
WS_CLOSE
WS_CLOSE
[WebSocket connection closed]
WebSocket JMAP connection on an HTTP/2 stream that also negotiates [
RFC 7692]:
[[ From Client ]] [[ From Server ]]
SETTINGS
SETTINGS_ENABLE_CONNECT_PROTOCOL = 1
HEADERS + END_HEADERS
:method = CONNECT
:protocol = websocket
:scheme = https
:path = /jmap/ws/
:authority = server.example.com
origin: https://example.com
authorization = Basic Zm9vOmJhcg==
sec-websocket-protocol = jmap
sec-websocket-version = 13
sec-websocket-extensions =
permessage-deflate
origin = https://www.example.com
HEADERS + END_HEADERS
:status = 200
sec-websocket-protocol = jmap
sec-websocket-extensions =
permessage-deflate
[WebSocket connection established]
DATA
WS_DATA
[compressed text]
DATA
WS_DATA
[compressed text]
...
DATA + END_STREAM
WS_CLOSE
DATA + END_STREAM
WS_CLOSE
[WebSocket connection closed]
[HTTP/2 stream closed]