Struct rotor_http::client::Request [] [src]

pub struct Request<'a>(_, pub Option<bool>);

Methods

impl<'a> Request<'a>
[src]

Creates new response message by extracting needed fields from Head

Write request line

This puts request line into a buffer immediately. If you don't continue with request it will be sent to the network shortly.

Panics

When request line is already written. It's expected that your request handler state machine will never call the method twice.

Add header to message

Header is written into the output buffer immediately. And is sent as soon as the next loop iteration

Content-Length header must be send using the add_length method and Transfer-Encoding: chunked must be set with the add_chunked method. These two headers are important for the security of HTTP.

Note that there is currently no way to use a transfer encoding other than chunked.

We return Result here to make implementing proxies easier. In the application handler it's okay to unwrap the result and to get a meaningful panic (that is basically an assertion).

Panics

Panics when add_header is called in the wrong state.

Add a content length to the message.

The Content-Length header is written to the output buffer immediately. It is checked that there are no other body length headers present in the message. When the body is send the length is validated.

Panics

Panics when add_length is called in the wrong state.

Sets the transfer encoding to chunked.

Writes Transfer-Encoding: chunked to the output buffer immediately. It is assured that there is only one body length header is present and the body is written in chunked encoding.

Panics

Panics when add_chunked is called in the wrong state.

Returns true if at least status() method has been called

This is mostly useful to find out whether we can build an error page or it's already too late.

Checks the validity of headers. And returns true if entity body is expected.

Specifically false is returned when status is 101, 204, 304 or the request is HEAD. Which means in both cases where response body is either ignored (304, HEAD) or is denied by specification. But not when response is zero-length.

Similarly to add_header() it's fine to unwrap() here, unless you're doing some proxying.

Panics

Panics when response is in a wrong state

Write a chunk of the body

Works both for fixed-size body and chunked body.

For the chunked body each chunk is put into the buffer immediately prefixed by chunk size.

For both modes chunk is put into the buffer, but is only sent when rotor-stream state machine is reached. So you may put multiple chunks into the buffer quite efficiently.

For Ignored body you can write_body any number of times, it's just ignored. But it's more efficient to check it with needs_body()

Panics

When response is in wrong state. Or there is no headers which determine response body length (either Content-Length or Transfer-Encoding)

Returns true if done() method is already called and everything was okay.

Writes needed final finalization data into the buffer and asserts that response is in the appropriate state for that.

The method may be called multiple times

Panics

When the response is in the wrong state or when Content-Length bytes are not written yet

Trait Implementations

impl<'a> From<Message<'a>> for Request<'a>
[src]

Performs the conversion.