Expand description
The HTTP side of the streaming server on top of hyper: short responses and the upgrade of a request to a WebSocket. The WebSocket handshake checks the request like RFC 6455 says, a request which does not pass gets a plain text response which tells what is missing.
Modulesยง
- accept_
key ๐ - The
Sec-WebSocket-Acceptheader of the WebSocket handshake.
Structsยง
- Body ๐
- The body of a response. The server sends short texts only, at once.
- Client
Io ๐ - The connection of a WebSocket client, whose input can get dropped
instead of read, see
Discard. - Close
Frame ๐ - A struct representing the close command.
- Discard ๐
- Drops the input of a
ClientIo, also after its WebSocket got split. A client which sent a message larger than the server takes may still be busy writing the rest of it and not read meanwhile, which holds up the status and the close for it, unless its input gets read. The WebSocket cannot read it anymore, it fails on the message again. Writes drop what the client sent before they write, up toDRAIN_LIMIT, and the input of the client wakes a write which waits for it. Reads see nothing but the end of the connection. - Discard
State ๐ - WebSocket
Upgrade ๐ - A request which asks for a WebSocket, checked like RFC 6455 says.
Enumsยง
- Client
Message ๐ - What a read of a WebSocket client gave, see
next_message. - Close
Code ๐ - Status code used to indicate why an endpoint is closing the WebSocket connection.
- End ๐
- How a WebSocket session ended, which decides what its end waits for, see
end. - Error ๐
- Possible WebSocket errors.
- Message ๐
- An enum representing the various forms of a WebSocket message.
Constantsยง
- CLOSE_
TIMEOUT ๐ - How long a client gets to answer the close of the server, and to end the
connection after a message which was too large, see
drain. - DRAIN_
LIMIT ๐ - The most a client may still send after the close for a message which was
too large, see
drain. More than the rest of a message of the size Kubernetes takes. - WEBSOCKET_
READ_ ๐BUFFER_ SIZE - The buffer a WebSocket reads into, which it allocates up front. Clients mostly send small stdin and resize events, larger messages grow it while they get read. Tungstenite allocates 128 KiB otherwise, for every session.
Functionsยง
- answer_
close ๐ - Answer the close of a client, which a read of
messagesjust returned. Tungstenite queues the answer, but writes it only with a later read or flush, and every send after the close fails without writing anything. The next read writes it, after what got queued before, and ends the stream. Without it the client sees the connection end without a close handshake. A slow client still gets it, one which takes nothing forSTALL_TIMEOUTdoes not, seeClientIo::written. - await_
close_ ๐answer - Read the client after the close of the server, until it answered the
close, for up to
CLOSE_TIMEOUT. What it sends meanwhile gets dropped. A socket closed with input it did not read resets the connection, which can drop what the client did not read yet, like the close and the output before it. - close ๐
- The close of the server once it is done, or after the client sent a
message larger than the server takes, see
is_too_large, which tells the client why. - drain ๐
- End a WebSocket whose client sent a message larger than the server
takes, once the close went out. The rest of the message cannot be read
as messages. The server stops writing and drops what the client still
sends until it ends the connection, for up to
CLOSE_TIMEOUTandDRAIN_LIMIT, on top of what got dropped while the close went out, seeDiscard. A socket closed with input it did not read resets the connection, which can drop the close and the status before it. - end ๐
- End a WebSocket session once its
writer, which sends the close of the server, got the rest out, seejoin_or_abort. What comes after depends on how it ended, seeEnd. - finish ๐
- End a WebSocket: wait for the writer, which sends the close of the
server, see
join_or_abort, then for the answer of the client, seeawait_close_answer. The writer returns its sink once its close went out, a client gets no time to answer a close it did not get. - header_
eq ๐ - Whether one of the values of the header is
value, ignoring the case. - header_
has_ ๐token - Whether one of the tokens of the header is
token, ignoring the case, seeheader_tokens. - header_
tokens ๐ - The comma separated tokens of all values of the header, without the
empty ones, like
keep-aliveandUpgradeofConnection: keep-alive, Upgrade. - is_
closed_ ๐by_ client - Whether a send failed after a close, which is the one of the client
while the server did not close yet, see
answer_close. - is_
too_ ๐large - Whether a read failed for a message larger than the server takes. The
WebSocket cannot be read anymore then, the rest of the message did not
get read, but the server can still close it, see
close, and has todrainit then. - join_
or_ ๐abort - Wait for the task which writes to a WebSocket and closes it, abort it
once the client did not take anything for
STALL_TIMEOUT, seeClientIo::written. A slow client still gets what is queued. Dropping its handle would leave it running, a writer to a client which does not read would hold the connection. The output of the writer,Noneif it did not end. - next_
message ๐ - Read the next message of a WebSocket client which the server handles, pings and pongs only keep the WebSocket alive. A client which sent a message larger than the server takes may still be busy writing the rest, which would hold up what the server sends, so its input gets dropped.
- send_
close ๐ - Send the close of the server without a reason, see
close, the sink once it went out. - status ๐
- A response with the status only.
- text ๐
- A response with a plain text, which tells the client what went wrong.
- write_
close_ ๐answer - Write the answer to the close of a client after a send failed for it,
if the read could not, see
answer_close.