conn
import std::net::http::conn; · source
Reading messages off a connection
implement struct BufStream<S> {
async read_request(mut &this) -> Result<Request, IoError>
where S: AsyncTransport;
async read_response(mut &this) -> Result<Response, IoError>
where S: AsyncTransport;
}
net::http::conn extends BufStream with the two message readers: request line or status line, headers until the blank line, then a body of exactly Content-Length bytes. Both cap what they will accept — header lines at MAX_HEADER_LINE, bodies at MAX_BODY — and fail with InvalidData past that.
They are methods on the connection rather than free functions for a reason that recurs across the async layers: a parser written as a static taking mut &BufStream<S> cannot be called from an async caller holding the connection as a local, because handing the address of a local to a future that outlives the current poll is refused (E0455). Only the receiver is re-supplied on every poll, so the reader has to be a method.
The server and client are written against these, and so can anything else that speaks HTTP/1.1 over a buffered transport — plaintext or TLS alike.