pub struct WebSocketUpgrade { /* private fields */ }Expand description
Creates a WebSocket Handler. Request:
- Method must be
GET - Header
connectionmust beupgrade - Header
upgrademust bewebsocket - Header
sec-websocket-versionmust be13 - Header
sec-websocket-keymust be set.
Response:
- Status of
101 Switching Protocols - Header
connection: upgrade - Header
upgrade: websocket - Header
sec-websocket-acceptwith the hash value of the received key.
Implementations§
Source§impl WebSocketUpgrade
impl WebSocketUpgrade
Sourcepub fn new() -> WebSocketUpgrade
pub fn new() -> WebSocketUpgrade
Create new WebSocketUpgrade.
Sourcepub fn with_config(config: WebSocketConfig) -> WebSocketUpgrade
pub fn with_config(config: WebSocketConfig) -> WebSocketUpgrade
Create new WebSocketUpgrade with config.
Sourcepub fn write_buffer_size(self, max: usize) -> WebSocketUpgrade
pub fn write_buffer_size(self, max: usize) -> WebSocketUpgrade
The target minimum size of the write buffer to reach before writing the data to the underlying stream. The default value is 128 KiB.
If set to 0 each message will be eagerly written to the underlying stream.
It is often more optimal to allow them to buffer a little, hence the default value.
Sourcepub fn max_write_buffer_size(self, max: usize) -> WebSocketUpgrade
pub fn max_write_buffer_size(self, max: usize) -> WebSocketUpgrade
The max size of the write buffer in bytes. Setting this can provide backpressure in the case the write buffer is filling up due to write errors. The default value is unlimited.
Note: The write buffer only builds up past write_buffer_size
when writes to the underlying stream are failing. So the write buffer can not
fill up if you are not observing write errors even if not flushing.
Should always be at least write_buffer_size + 1 message
and probably a little more depending on error handling strategy.
Sourcepub fn max_message_size(self, max: usize) -> WebSocketUpgrade
pub fn max_message_size(self, max: usize) -> WebSocketUpgrade
The maximum size of a message. None means no size limit. The default value is 64 MiB
which should be reasonably big for all normal use-cases but small enough to prevent
memory eating by a malicious user.
Sourcepub fn max_frame_size(self, max: usize) -> WebSocketUpgrade
pub fn max_frame_size(self, max: usize) -> WebSocketUpgrade
The maximum size of a single message frame. None means no size limit. The limit is for
frame payload NOT including the frame header. The default value is 16 MiB which should
be reasonably big for all normal use-cases but small enough to prevent memory eating
by a malicious user.
Sourcepub fn accept_unmasked_frames(self, accept: bool) -> WebSocketUpgrade
pub fn accept_unmasked_frames(self, accept: bool) -> WebSocketUpgrade
When set to true, the server will accept and handle unmasked frames
from the client. According to the RFC 6455, the server must close the
connection to the client in such cases, however it seems like there are
some popular libraries that are sending unmasked frames, ignoring the RFC.
By default this option is set to false, i.e. according to RFC 6455.