pub fn parse_client_message(
text: &str,
config: &ConnectionConfig,
) -> Result<ClientMessage, WsRequestError>Available on crate feature
server only.Expand description
Reads one text message from the client (RFC 8887 §4.3).
In order:
- Longer than
maxSizeRequest:limit(maxSizeRequest). - Not JSON:
notJSON, with the detail text of the RFC 8887 §4.4 example. - Not an object, or
@typemissing or not one ofRequest,WebSocketPushEnable,WebSocketPushDisable:notRequest. Request:id, when present, must be a string (§4.3.2), elsenotRequest; the rest must be an RFC 8620 §3.3 Request (jmap_server::parse_request:notRequest, orlimitformaxCallsInRequest).WebSocketPushEnable/WebSocketPushDisablewith members of the wrong type:notRequest.
Every error carries the message’s id as requestId when the message
is an object with a string id, and null otherwise, so the client
can correlate it (§4.3.4: “MUST be returned if given in the request”).
use jmap_websocket::ClientMessage;
use jmap_websocket::server::{ConnectionConfig, parse_client_message};
let config = ConnectionConfig::default();
let m = parse_client_message(r#"{"@type":"WebSocketPushDisable"}"#, &config).unwrap();
assert!(matches!(m, ClientMessage::PushDisable(_)));
let e = parse_client_message("The quick brown fox", &config).unwrap_err();
assert_eq!(e.problem.problem_type, "urn:ietf:params:jmap:error:notJSON");
assert_eq!(e.request_id, None);§Errors
The WsRequestError to send back, as listed above.