1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! JMAP over WebSocket, [RFC 8887](https://www.rfc-editor.org/rfc/rfc8887)
//! (`urn:ietf:params:jmap:websocket`).
//!
//! This is a support crate (workspace AGENTS.md §Support crates): no
//! `*-types` or `*-server` crate depends on it, and a deployment opts in.
//!
//! Always available, with no async runtime:
//!
//! - [`CAPABILITY`], [`SUBPROTOCOL`] and [`offers_jmap`] for the
//! Session object (§3) and the opening handshake (§4.2).
//! - [`WebSocketCapability`], the §3 capability object.
//! - The §4.3 messages: [`WsRequest`], [`WebSocketPushEnable`] and
//! [`WebSocketPushDisable`] from the client ([`ClientMessage`]);
//! [`WsResponse`], [`WsRequestError`] and [`WsStateChange`] from the
//! server ([`ServerMessage`]).
//!
//! Feature `server`: [`server::Connection`], a session driver that turns
//! incoming text frames into [`jmap_server::Dispatcher`] calls and writes
//! the answers and push notifications back, over any `Stream` and `Sink`
//! of messages, so it fits axum, tokio-tungstenite or another stack. Also
//! [`server::PushHub`], an in-memory state-change source with `pushState`
//! replay.
//!
//! Feature `tungstenite`: `tungstenite::serve` runs a connection over a
//! tokio-tungstenite `WebSocketStream`.
//!
//! The authenticated HTTP request that opens the WebSocket, and the TLS
//! under it (RFC 8887 §4.1, §5.1), are the deployment's.
pub use WebSocketCapability;
pub use ;
pub use jmap_types;
pub use futures;
pub use jmap_server;
pub use tokio_tungstenite;
/// The JMAP capability URI of this extension (RFC 8887 §3, §6): the key
/// of [`WebSocketCapability`] in the Session's `capabilities`.
pub const CAPABILITY: &str = "urn:ietf:params:jmap:websocket";
/// The WebSocket subprotocol name (RFC 8887 §4.2, §6.1). The client MUST
/// list it in `Sec-WebSocket-Protocol`, and the server's reply MUST carry
/// it for a JMAP connection to be established.
pub const SUBPROTOCOL: &str = "jmap";
/// Whether a `Sec-WebSocket-Protocol` request header value lists the
/// [`SUBPROTOCOL`] (RFC 8887 §4.2).
///
/// The header is a comma-separated list of tokens (RFC 6455 §11.3.4);
/// tokens are compared exactly, since subprotocol names are
/// case-sensitive. A server that gets `false` must not complete the
/// handshake as a JMAP connection.
///
/// ```
/// assert!(jmap_websocket::offers_jmap("chat, jmap"));
/// assert!(!jmap_websocket::offers_jmap("JMAP"));
/// ```