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

source§

fn clone(&self) -> HttpClientCodec

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for HttpClientCodec

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Decoder for HttpClientCodec

§

type Item = Incoming<RawStatus>

The type of decoded frames.
§

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>

Attempts to decode a frame from the provided buffer of bytes. Read more
source§

fn decode_eof( &mut self, buf: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>

A default method available to be called when there are no more bytes available to be read from the underlying I/O. Read more
source§

fn framed<T>(self, io: T) -> Framed<T, Self>
where T: AsyncRead + AsyncWrite, Self: Encoder + Sized,

Provides a Stream and Sink interface for reading and writing to this Io object, using Decode and Encode to read and write the raw data. Read more
source§

impl Encoder for HttpClientCodec

§

type Item = Incoming<(Method, RequestUri)>

The type of items consumed by the Encoder
§

type Error = Error

The type of encoding errors. Read more
source§

fn encode( &mut self, item: Self::Item, dst: &mut BytesMut ) -> Result<(), Self::Error>

Encodes a frame into the buffer provided. Read more
source§

impl Copy for HttpClientCodec

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Typeable for T
where T: Any,

source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.