Trait tk_http::server::Codec [] [src]

pub trait Codec<S> {
    type ResponseFuture: Future<Item = EncoderDone<S>, Error = Error>;
    fn recv_mode(&mut self) -> RecvMode;
fn data_received(
        &mut self,
        data: &[u8],
        end: bool
    ) -> Result<Async<usize>, Error>;
fn start_response(&mut self, e: Encoder<S>) -> Self::ResponseFuture; fn hijack(&mut self, _output: WriteBuf<S>, _input: ReadBuf<S>) { ... } }

The type represents a consumer of a single request and yields a writer of a response (the latter is a ResponseFuture

Associated Types

This is a future returned by start_response

It's fine if it's just Box<Future<Item=EncoderDone<S>, Error>> in most cases.

Required Methods

Return a mode which will be used to receive request body

Note: this mode not only influences the size of chunks that data_received recieves and amount of buffering, but also it constrains the sequence between calls of start_response() and data_received().

Called once, right after headers_received

Chunk of the response body received

end equals to true for the last chunk of the data.

Method returns Async::Ready(x) to denote that it has consumed x bytes. If there are some bytes left in the buffer they will be passed again on the call.

If the response is empty, or last chunk arrives later and it's empty we call c.data_received(b"", true) on every wakeup, until Async::Ready(0) is returned (this helps to drive future that might complete on response completion without spawning another ones, but note that next response can't start writing in the meantime).

Protocol panics if returned number of bytes larger than data.len().

Start writing a response

This method is called when there all preceding requests are either send to the network or already buffered. It can be called before data_received() but not before headers_received() (that would not make sense).

Everything you write into a buffer might be flushed to the network immediately (or as fast as you yield to main loop). On the other hand we might buffer/pipeline multiple responses at once.

Provided Methods

Called after future retunrted by start_response done if recv mode is Hijack

Note: both input and output buffers can contain some data.

Implementations on Foreign Types

impl<S, F> Codec<S> for Box<Codec<S, ResponseFuture = F>> where
    F: Future<Item = EncoderDone<S>, Error = Error>, 
[src]

[src]

[src]

[src]

[src]

Implementors