pub struct Conn { /* private fields */ }Expand description
One accepted connection: the socket plus its receive buffer, which persists across requests — keep-alive drains exactly one request’s frame per parse and keeps the remainder (a pipelined next request) buffered, and the allocation is reused for every request on the connection.
Implementations§
Source§impl Conn
impl Conn
Sourcepub async fn read_request(&mut self) -> Result<HttpRequest, ReadError>
pub async fn read_request(&mut self) -> Result<HttpRequest, ReadError>
Read and parse the next complete request, growing the connection buffer
until the header block and Content-Length body have arrived (bounded by
the wire core’s MAX_HEADERS/MAX_BODY). Consumes exactly the request’s
frame from the buffer; pipelined bytes stay for the next call.
Sourcepub async fn read_request_capped(
&mut self,
max_body: usize,
) -> Result<HttpRequest, ReadError>
pub async fn read_request_capped( &mut self, max_body: usize, ) -> Result<HttpRequest, ReadError>
Conn::read_request, but with a per-server max_body cap that is
TIGHTER than the wire core’s global super::wire::MAX_BODY: the instant
the header block has arrived, the declared Content-Length is checked
against max_body and an over-limit request is rejected with
ParseError::BodyTooLarge BEFORE the promised body bytes are ever
buffered — a client cannot make the server hold megabytes for a body it
declared past the cap. Everything else is the identical parse.
Sourcepub async fn write_response(&mut self, resp: &HttpResponse) -> Result<()>
pub async fn write_response(&mut self, resp: &HttpResponse) -> Result<()>
Serialize and write a one-shot (Connection: close) response, then flush.
Sourcepub async fn write_response_conn(
&mut self,
resp: &HttpResponse,
keep_alive: bool,
) -> Result<()>
pub async fn write_response_conn( &mut self, resp: &HttpResponse, keep_alive: bool, ) -> Result<()>
Serialize and write a response with an explicit connection disposition
(Connection: keep-alive holds the connection for the next
Conn::read_request; close ends it), then flush.
Sourcepub async fn upgrade(self, response: String, handler: UpgradeHandler)
pub async fn upgrade(self, response: String, handler: UpgradeHandler)
Complete an upgrade try_upgrade accepted: write its 101 response, then hand the socket
— with whatever was read past the request — to its handler, spawned as its own task. The
one hand-off every connection loop makes, the tokio engine’s and the interpreter’s alike.