pub struct WsUpgrade<S, B> where
S: Stream, {
pub headers: Headers,
pub stream: S,
pub request: Request,
pub buffer: B,
}
Expand description
Intermediate representation of a half created websocket session. Should be used to examine the client’s handshake accept the protocols requested, route the path, etc.
Users should then call accept
or reject
to complete the handshake
and start a session.
Note: if the stream in use is AsyncRead + AsyncWrite
, then asynchronous
functions will be available when completing the handshake.
Otherwise if the stream is simply Read + Write
blocking functions will be
available to complete the handshake.
Fields
headers: Headers
The headers that will be used in the handshake response.
stream: S
The stream that will be used to read from / write to.
request: Request
The handshake request, filled with useful metadata.
buffer: B
Some buffered data from the stream, if it exists.
Implementations
sourceimpl<S> WsUpgrade<S, BytesMut> where
S: Stream + Send + 'static,
impl<S> WsUpgrade<S, BytesMut> where
S: Stream + Send + 'static,
These are the extra functions given to WsUpgrade
with the async
feature
turned on. A type alias for this specialization of WsUpgrade
lives in this
module under the name Upgrade
.
sourcepub fn accept(self) -> ClientNew<S>
pub fn accept(self) -> ClientNew<S>
Asynchronously accept the websocket handshake, then create a client. This will asynchronously send a response accepting the connection and create a websocket client.
sourcepub fn accept_with(self, custom_headers: &Headers) -> ClientNew<S>
pub fn accept_with(self, custom_headers: &Headers) -> ClientNew<S>
Asynchronously accept the websocket handshake, then create a client. This will asynchronously send a response accepting the connection with custom headers in the response and create a websocket client.
sourcepub fn accept_with_limits(
self,
max_dataframe_size: usize,
max_message_size: usize
) -> ClientNew<S>
pub fn accept_with_limits(
self,
max_dataframe_size: usize,
max_message_size: usize
) -> ClientNew<S>
Like accept
, but also allows to set memory limits for incoming messages and dataframes
sourcepub fn accept_with_headers_and_limits(
self,
custom_headers: &Headers,
max_dataframe_size: usize,
max_message_size: usize
) -> ClientNew<S>
pub fn accept_with_headers_and_limits(
self,
custom_headers: &Headers,
max_dataframe_size: usize,
max_message_size: usize
) -> ClientNew<S>
Like accept_with
, but also allows to set memory limits for incoming messages and dataframes
sourcepub fn reject(self) -> SinkSend<Framed<S, HttpServerCodec>>
pub fn reject(self) -> SinkSend<Framed<S, HttpServerCodec>>
Asynchronously send a rejection message and deconstruct self
into it’s original stream. The stream being returned is framed with the
HttpServerCodec
since that was used to send the rejection message.
sourcepub fn reject_with(
self,
headers: &Headers
) -> SinkSend<Framed<S, HttpServerCodec>>
pub fn reject_with(
self,
headers: &Headers
) -> SinkSend<Framed<S, HttpServerCodec>>
Asynchronously send a rejection message with custom headers and
deconstruct self
into it’s original stream.
The stream being returned is framed with the
HttpServerCodec
since that was used to send the rejection message.
sourceimpl<S> WsUpgrade<S, Option<Buffer>> where
S: Stream,
impl<S> WsUpgrade<S, Option<Buffer>> where
S: Stream,
These methods are the synchronous ways of accepting and rejecting a websocket handshake.
sourcepub fn accept(self) -> Result<Client<S>, (S, Error)>
pub fn accept(self) -> Result<Client<S>, (S, Error)>
Accept the handshake request and send a response, if nothing goes wrong a client will be created.
sourcepub fn accept_with(
self,
custom_headers: &Headers
) -> Result<Client<S>, (S, Error)>
pub fn accept_with(
self,
custom_headers: &Headers
) -> Result<Client<S>, (S, Error)>
Accept the handshake request and send a response while adding on a few headers. These headers are added before the required headers are, so some might be overwritten.
sourcepub fn accept_with_limits(
self,
max_dataframe_size: usize,
max_message_size: usize
) -> Result<Client<S>, (S, Error)>
pub fn accept_with_limits(
self,
max_dataframe_size: usize,
max_message_size: usize
) -> Result<Client<S>, (S, Error)>
Accept the handshake request and send a response, if nothing goes wrong a client will be created.
sourcepub fn accept_with_headers_and_limits(
self,
custom_headers: &Headers,
max_dataframe_size: usize,
max_message_size: usize
) -> Result<Client<S>, (S, Error)>
pub fn accept_with_headers_and_limits(
self,
custom_headers: &Headers,
max_dataframe_size: usize,
max_message_size: usize
) -> Result<Client<S>, (S, Error)>
Accept the handshake request and send a response while adding on a few headers. These headers are added before the required headers are, so some might be overwritten.
sourcepub fn reject(self) -> Result<S, (S, Error)>
pub fn reject(self) -> Result<S, (S, Error)>
Reject the client’s request to make a websocket connection.
sourcepub fn reject_with(self, headers: &Headers) -> Result<S, (S, Error)>
pub fn reject_with(self, headers: &Headers) -> Result<S, (S, Error)>
Reject the client’s request to make a websocket connection and send extra headers.
sourceimpl<S, B> WsUpgrade<S, B> where
S: Stream + AsTcpStream,
impl<S, B> WsUpgrade<S, B> where
S: Stream + AsTcpStream,
sourceimpl<S, B> WsUpgrade<S, B> where
S: Stream,
impl<S, B> WsUpgrade<S, B> where
S: Stream,
sourcepub fn use_protocol<P>(self, protocol: P) -> Self where
P: Into<String>,
pub fn use_protocol<P>(self, protocol: P) -> Self where
P: Into<String>,
Select a protocol to use in the handshake response.
sourcepub fn use_extension(self, extension: Extension) -> Self
pub fn use_extension(self, extension: Extension) -> Self
Select an extension to use in the handshake response.
sourcepub fn use_extensions<I>(self, extensions: I) -> Self where
I: IntoIterator<Item = Extension>,
pub fn use_extensions<I>(self, extensions: I) -> Self where
I: IntoIterator<Item = Extension>,
Select multiple extensions to use in the connection
sourcepub fn extensions(&self) -> &[Extension]
pub fn extensions(&self) -> &[Extension]
A list of extensions requested from the client.
sourcepub fn version(&self) -> Option<&WebSocketVersion>
pub fn version(&self) -> Option<&WebSocketVersion>
The client’s websocket version.
Auto Trait Implementations
impl<S, B> !RefUnwindSafe for WsUpgrade<S, B>
impl<S, B> Send for WsUpgrade<S, B> where
B: Send,
S: Send,
impl<S, B> !Sync for WsUpgrade<S, B>
impl<S, B> Unpin for WsUpgrade<S, B> where
B: Unpin,
S: Unpin,
impl<S, B> !UnwindSafe for WsUpgrade<S, B>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more