pub struct HttpClientCodec;
Expand description
A codec to be used with tokio
codecs that can serialize HTTP requests and
deserialize HTTP responses. One can use this on it’s own without websockets to
make a very bare async HTTP server.
Example
use websocket::r#async::HttpClientCodec;
let mut runtime = tokio::runtime::Builder::new().build().unwrap();
let addr = "crouton.net".parse().unwrap();
let f = TcpStream::connect(&addr)
.and_then(|s| {
Ok(HttpClientCodec.framed(s))
})
.and_then(|s| {
s.send(Incoming {
version: HttpVersion::Http11,
subject: (Method::Get, RequestUri::AbsolutePath("/".to_string())),
headers: Headers::new(),
})
})
.map_err(|e| e.into())
.and_then(|s| s.into_future().map_err(|(e, _)| e))
.map(|(m, _)| println!("You got a crouton: {:?}", m));
runtime.block_on(f).unwrap();
Trait Implementations
sourceimpl Clone for HttpClientCodec
impl Clone for HttpClientCodec
sourcefn clone(&self) -> HttpClientCodec
fn clone(&self) -> HttpClientCodec
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 HttpClientCodec
impl Debug for HttpClientCodec
sourceimpl Decoder for HttpClientCodec
impl Decoder for HttpClientCodec
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 HttpClientCodec
impl Encoder for HttpClientCodec
impl Copy for HttpClientCodec
Auto Trait Implementations
impl RefUnwindSafe for HttpClientCodec
impl Send for HttpClientCodec
impl Sync for HttpClientCodec
impl Unpin for HttpClientCodec
impl UnwindSafe for HttpClientCodec
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)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more