Struct websocket::codec::http::HttpServerCodec
source · pub struct HttpServerCodec;
Expand description
A codec that can be used with streams implementing AsyncRead + AsyncWrite
that can serialize HTTP responses and deserialize HTTP requests. Using this
with an async TcpStream
will give you a very bare async HTTP server.
This crate sends out one HTTP request / response in order to perform the websocket handshake then never talks HTTP again. Because of this an async HTTP implementation is needed.
§Example
use websocket::r#async::HttpServerCodec;
let mut runtime = tokio::runtime::Builder::new().build().unwrap();
let addr = "nothing-to-see-here.com".parse().unwrap();
let f = TcpStream::connect(&addr)
.map(|s| HttpServerCodec.framed(s))
.map_err(|e| e.into())
.and_then(|s| s.into_future().map_err(|(e, _)| e))
.and_then(|(m, s)| match m {
Some(ref m) if m.subject.0 == Method::Get => Ok(s),
_ => panic!(),
})
.and_then(|stream| {
stream
.send(Incoming {
version: HttpVersion::Http11,
subject: StatusCode::NotFound,
headers: Headers::new(),
})
.map_err(|e| e.into())
});
runtime.block_on(f).unwrap();
Trait Implementations§
source§impl Clone for HttpServerCodec
impl Clone for HttpServerCodec
source§fn clone(&self) -> HttpServerCodec
fn clone(&self) -> HttpServerCodec
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for HttpServerCodec
impl Debug for HttpServerCodec
source§impl Decoder for HttpServerCodec
impl Decoder for HttpServerCodec
§type Item = Incoming<(Method, RequestUri)>
type Item = Incoming<(Method, RequestUri)>
The type of decoded frames.
§type Error = HttpCodecError
type Error = HttpCodecError
The type of unrecoverable frame decoding errors. Read more
source§fn decode(
&mut self,
src: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
fn decode( &mut self, src: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>
Attempts to decode a frame from the provided buffer of bytes. Read more
source§impl Encoder for HttpServerCodec
impl Encoder for HttpServerCodec
impl Copy for HttpServerCodec
Auto Trait Implementations§
impl Freeze for HttpServerCodec
impl RefUnwindSafe for HttpServerCodec
impl Send for HttpServerCodec
impl Sync for HttpServerCodec
impl Unpin for HttpServerCodec
impl UnwindSafe for HttpServerCodec
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more