[−][src]Trait websocket::server::upgrade::sync::IntoWs
Trait to take a stream or similar and attempt to recover the start of a websocket handshake from it. Should be used when a stream might contain a request for a websocket session.
If an upgrade request can be parsed, one can accept or deny the handshake with
the WsUpgrade
struct.
Otherwise the original stream is returned along with an error.
Note: the stream is owned because the websocket client expects to own its stream.
This is already implemented for all Streams, which means all types with Read + Write.
Example
use std::net::TcpListener; use std::net::TcpStream; use websocket::sync::server::upgrade::IntoWs; use websocket::sync::Client; let listener = TcpListener::bind("127.0.0.1:80").unwrap(); for stream in listener.incoming().filter_map(Result::ok) { let mut client: Client<TcpStream> = match stream.into_ws() { Ok(upgrade) => { match upgrade.accept() { Ok(client) => client, Err(_) => panic!(), } }, Err(_) => panic!(), }; }
Associated Types
type Stream: Stream
The type of stream this upgrade process is working with (TcpStream, etc.)
type Error
An error value in case the stream is not asking for a websocket connection or something went wrong. It is common to also include the stream here.
Required Methods
fn into_ws(self) -> Result<Upgrade<Self::Stream>, Self::Error>
Attempt to parse the start of a Websocket handshake, later with the returned
WsUpgrade
struct, call accept
to start a websocket client, and reject
to
send a handshake rejection response.
Implementors
impl<'a, 'b> IntoWs for HyperRequest<'a, 'b>
[src]
impl<'a, 'b> IntoWs for HyperRequest<'a, 'b>
type Stream = &'a mut &'b mut dyn NetworkStream
type Error = (Request<'a, 'b>, HyperIntoWsError)
fn into_ws(self) -> Result<Upgrade<Self::Stream>, Self::Error>
[src]
fn into_ws(self) -> Result<Upgrade<Self::Stream>, Self::Error>
impl<S> IntoWs for RequestStreamPair<S> where
S: Stream,
[src]
impl<S> IntoWs for RequestStreamPair<S> where
S: Stream,
type Stream = S
type Error = (S, Request, HyperIntoWsError)
fn into_ws(self) -> Result<Upgrade<Self::Stream>, Self::Error>
[src]
fn into_ws(self) -> Result<Upgrade<Self::Stream>, Self::Error>
impl<S> IntoWs for S where
S: Stream,
[src]
impl<S> IntoWs for S where
S: Stream,