adapter library
What an adapter implementation needs beyond relic_core.dart.
The Adapter contract itself, with AdapterExchange, Listener and
RelicWebSocket, is in package:relic_core/relic_core.dart, since the
server names those types. This library carries the toolkit for
implementing them: response framing and head encoding, the WebSocket
wire format and the framed socket over a byte channel.
Classes
- FramedWebSocket
- A RelicWebSocket framed in Dart over a raw byte channel, for an adapter that can hand a connection over but has no framer of its own.
- RelicWebSocketBase
- What every RelicWebSocket over a framing transport shares: the events the handler reads, the send and close guards, the going-away close and the ping timer.
- ResponseFraming
- What goes on the wire for a Response, decided once so every adapter frames the same bytes for the same response.
- ResponseHead
- The status line and header block of a response, sized before it is written so the caller can put it straight into the buffer the native side takes over.
- WebSocketBinary
- A binary message.
- WebSocketControl
- A ping, pong or close frame, which passes through the assembler at once, even in the middle of a fragmented message.
- WebSocketFrame
- One frame off the wire, unmasked.
- WebSocketFrameDecoder
- Splits a byte stream from a client into frames.
- WebSocketInbound
- What WebSocketMessageAssembler.add hands out: a complete message, or a control frame as it came.
- WebSocketMessageAssembler
- Joins fragments into messages and decodes text.
- WebSocketText
- A text message.
Enums
- WebSocketOpcode
- RFC 6455 5.2 opcodes.
Mixins
- ExchangeEndState
- How an exchange ended, recorded once, with done for a caller that asked before then.
Constants
- stampedDate → const String
- A stand-in for an IMF-fixdate that an adapter overwrites on the wire, at send time. It has the 29 bytes every IMF-fixdate has, so the head keeps its length, and it is a real date in case it ever gets out.
Functions
-
checkCloseCode(
int? code) → void -
Throws ArgumentError unless
codeis one this side may close with: none, 1000, 1001, or 3000 to 4999. -
checkCloseReason(
String? reason) → void -
Throws ArgumentError when
reasonis over 123 bytes as UTF-8. -
decodeClosePayload(
Uint8List payload) → ({int code, String reason}) - The inverse of encodeClosePayload.
-
encodeClosePayload(
int? code, String reason) → Uint8List - The payload of a close frame: the code, then the reason in UTF-8, or nothing at all when there is no code.
-
encodeResponseHead(
Response response, ResponseFraming framing) → Uint8List -
The head of
responseas bytes, framed byframing, for an adapter that writes it from its own buffer. -
encodeWebSocketFrame(
WebSocketOpcode opcode, List< int> payload, {bool fin = true}) → Uint8List - Encodes a server frame, which is never masked (RFC 6455 5.1).
-
httpDateLineOf(
String value) → Uint8List? -
The field line of
value,date: <value>\r\n, whenvalueis what httpDate last returned, else null. No clock read. The caller copies the line and does not write into it. -
isValidCloseCode(
int code) → bool -
Whether
codeis one a peer may send in a close frame (RFC 6455 7.4 and the IANA registry). -
statusMayHaveBody(
int status) → bool -
Whether a response with
statuscarries a body on the wire. 1xx, 204 and 304 responses have none, and no Content-Length either. -
webSocketAcceptKey(
Request request) → String? -
The
Sec-WebSocket-Acceptvalue forrequest, or null when the request is not a WebSocket opening handshake a server can accept (RFC 6455 4.2.1). -
webSocketHandshakeResponse(
String acceptKey) → Uint8List - The 101 response that completes the handshake, as bytes for the wire.
Exceptions / Errors
- WebSocketProtocolException
- A peer that broke the framing rules.