Struct websocket::codec::http::HttpClientCodec
source · 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§
source§impl Clone for HttpClientCodec
impl Clone for HttpClientCodec
source§fn clone(&self) -> HttpClientCodec
fn clone(&self) -> HttpClientCodec
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 HttpClientCodec
impl Debug for HttpClientCodec
source§impl Decoder for HttpClientCodec
impl Decoder for HttpClientCodec
§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 HttpClientCodec
impl Encoder for HttpClientCodec
impl Copy for HttpClientCodec
Auto Trait Implementations§
impl Freeze for HttpClientCodec
impl RefUnwindSafe for HttpClientCodec
impl Send for HttpClientCodec
impl Sync for HttpClientCodec
impl Unpin for HttpClientCodec
impl UnwindSafe for HttpClientCodec
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