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
sourceimpl Clone for HttpServerCodec
impl Clone for HttpServerCodec
sourcefn clone(&self) -> HttpServerCodec
fn clone(&self) -> HttpServerCodec
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for HttpServerCodec
impl Debug for HttpServerCodec
sourceimpl Decoder for HttpServerCodec
impl Decoder for HttpServerCodec
type Error = HttpCodecError
type Error = HttpCodecError
The type of unrecoverable frame decoding errors. Read more
sourcefn 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
sourceimpl Encoder for HttpServerCodec
impl Encoder for HttpServerCodec
impl Copy for HttpServerCodec
Auto Trait Implementations
impl RefUnwindSafe for HttpServerCodec
impl Send for HttpServerCodec
impl Sync for HttpServerCodec
impl Unpin for HttpServerCodec
impl UnwindSafe for HttpServerCodec
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more