Skip to main content

Module har

Module har 

Available on crate features http and std and ws only.
Expand description

HAR capture middleware for WebSocket message streams.

This module deliberately decorates an already constructed WebSocket. The core WebSocket runtime and protocol implementation do not know about HAR, recorders, or HTTP middleware extensions.

HARWebSocketLayer is explicitly installed around a service that accepts a client endpoint, server endpoint, or established relay bridge. Manual handshake users can instead apply ClientWebSocket::map_socket or ServerWebSocket::map_socket and construct HARWebSocket directly. Code that does not apply either form keeps using the ordinary WebSocket types and pays no capture-wrapper cost.

A relay capture records the messages finally accepted by its destination legs: writes to the upstream-facing egress socket are HAR send messages, while writes to the downstream-facing ingress socket are HAR receive messages. Messages dropped by relay middleware are therefore absent, and transformed or expanded outputs are represented as actually forwarded. The opaque capture handle is carried by the egress transport because it continues the HAR session created around the upstream HTTP handshake. Once claimed, that one session is shared by the wrappers on both bridge legs; its egress location does not limit observation to egress traffic.

In an endpoint stack, apply this layer to the service that consumes a ClientWebSocket or ServerWebSocket. The layer reads the opaque capture handle from that wrapper’s preserved HTTP handshake metadata, replaces only its generic socket parameter, and calls the inner endpoint. For a relay, place the same layer between WebSocketRelayIoService and a message-level relay service:

BridgeIo<raw ingress, raw egress>
    -> WebSocketRelayIoService
    -> HARWebSocketLayer
    -> WebSocketRelayService

A manual client can clone WebSocketCapture from websocket.response().extensions and pass it to HARWebSocket::new through ClientWebSocket::map_socket. The equivalent server metadata is available through websocket.request().extensions. No HAR-specific extension trait or handshake variant is required.

Structs§

HARWebSocket
HAR-capturing middleware around a WebSocket message stream.
HARWebSocketLayer
Rama layer that installs HAR capture around WebSocket endpoint services or an established relay bridge.
HARWebSocketService
Service produced by HARWebSocketLayer.