Skip to main content

Conn

Struct Conn 

Source
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

Source

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.

Source

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.

Source

pub async fn write_response(&mut self, resp: &HttpResponse) -> Result<()>

Serialize and write a one-shot (Connection: close) response, then flush.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl !Freeze for Conn

§

impl RefUnwindSafe for Conn

§

impl Send for Conn

§

impl Sync for Conn

§

impl Unpin for Conn

§

impl UnsafeUnpin for Conn

§

impl UnwindSafe for Conn

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,