Skip to main content

parse_client_message

Function parse_client_message 

Source
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:

  1. Longer than maxSizeRequest: limit (maxSizeRequest).
  2. Not JSON: notJSON, with the detail text of the RFC 8887 §4.4 example.
  3. Not an object, or @type missing or not one of Request, WebSocketPushEnable, WebSocketPushDisable: notRequest.
  4. Request: id, when present, must be a string (§4.3.2), else notRequest; the rest must be an RFC 8620 §3.3 Request (jmap_server::parse_request: notRequest, or limit for maxCallsInRequest).
  5. WebSocketPushEnable / WebSocketPushDisable with 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.