[−][src]Struct websocket::server::upgrade::sync::HyperRequest
Upgrade a hyper connection to a websocket one.
A hyper request is implicitly defined as a stream from other impl
s of Stream.
Until trait impl specialization comes along, we use this struct to differentiate
a hyper request (which already has parsed headers) from a normal stream.
Using this method, one can start a hyper server and check if each request is a websocket upgrade request, if so you can use websockets and hyper on the same port!
use hyper::server::{Server, Request, Response}; use websocket::Message; use websocket::sync::server::upgrade::IntoWs; use websocket::sync::server::upgrade::HyperRequest; Server::http("0.0.0.0:80").unwrap().handle(move |req: Request, res: Response| { match HyperRequest(req).into_ws() { Ok(upgrade) => { // `accept` sends a successful handshake, no need to worry about res let mut client = match upgrade.accept() { Ok(c) => c, Err(_) => panic!(), }; client.send_message(&Message::text("its free real estate")); }, Err((request, err)) => { // continue using the request as normal, "echo uri" res.send(b"Try connecting over ws instead.").unwrap(); }, }; }) .unwrap();
Trait Implementations
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
The type of stream this upgrade process is working with (TcpStream, etc.)
type Error = (Request<'a, 'b>, HyperIntoWsError)
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. Read more
fn into_ws(self) -> Result<Upgrade<Self::Stream>, Self::Error>
[src]
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. Read more
Auto Trait Implementations
impl<'a, 'b> Send for HyperRequest<'a, 'b>
impl<'a, 'b> Send for HyperRequest<'a, 'b>
impl<'a, 'b> !Sync for HyperRequest<'a, 'b>
impl<'a, 'b> !Sync for HyperRequest<'a, 'b>
Blanket Implementations
impl<S> IntoWs for S where
S: Stream,
[src]
impl<S> IntoWs for S where
S: Stream,
type Stream = S
The type of stream this upgrade process is working with (TcpStream, etc.)
type Error = (S, Option<Incoming<(Method, RequestUri)>>, Option<Buffer>, HyperIntoWsError)
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. Read more
fn into_ws(
Self
) -> Result<WsUpgrade<<S as IntoWs>::Stream, Option<Buffer>>, <S as IntoWs>::Error>
[src]
fn into_ws(
Self
) -> Result<WsUpgrade<<S as IntoWs>::Stream, Option<Buffer>>, <S as IntoWs>::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. Read more
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Typeable for T where
T: Any,
[src]
impl<T> Typeable for T where
T: Any,
impl<T> Erased for T
[src]
impl<T> Erased for T