Skip to main content

Module web

Module web 

Source
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-Accept header of the WebSocket handshake.

Structsยง

Body ๐Ÿ”’
The body of a response. The server sends short texts only, at once.
ClientIo ๐Ÿ”’
The connection of a WebSocket client, whose input can get dropped instead of read, see Discard.
CloseFrame ๐Ÿ”’
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 to DRAIN_LIMIT, and the input of the client wakes a write which waits for it. Reads see nothing but the end of the connection.
DiscardState ๐Ÿ”’
WebSocketUpgrade ๐Ÿ”’
A request which asks for a WebSocket, checked like RFC 6455 says.

Enumsยง

ClientMessage ๐Ÿ”’
What a read of a WebSocket client gave, see next_message.
CloseCode ๐Ÿ”’
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 messages just 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 for STALL_TIMEOUT does not, see ClientIo::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_TIMEOUT and DRAIN_LIMIT, on top of what got dropped while the close went out, see Discard. 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, see join_or_abort. What comes after depends on how it ended, see End.
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, see await_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, see header_tokens.
header_tokens ๐Ÿ”’
The comma separated tokens of all values of the header, without the empty ones, like keep-alive and Upgrade of Connection: 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 to drain it 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, see ClientIo::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, None if 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.

Type Aliasesยง

Response ๐Ÿ”’
A response of the streaming server.
WebSocket ๐Ÿ”’
A WebSocket of a client, after the upgrade of its request.