Skip to main content

Connection

Struct Connection 

Source
pub struct Connection {
    pub our_role: Role,
    pub their_role: Role,
    pub their_http_version: Option<Vec<u8>>,
    /* private fields */
}
Expand description

Sans-I/O HTTP/1.1 connection state machine.

A Connection owns parser and serializer state for one endpoint role. It does not perform I/O directly: callers supply received bytes with Connection::receive_data, consume inbound events with Connection::next_event, and write bytes returned by Connection::send to their transport.

Fields§

§our_role: Role

Role represented by this connection object.

§their_role: Role

Peer role.

§their_http_version: Option<Vec<u8>>

Most recently observed peer HTTP version, without the HTTP/ prefix.

Implementations§

Source§

impl Connection

Source

pub fn new(our_role: Role, max_incomplete_event_size: Option<usize>) -> Self

Creates a connection for the given local role.

max_incomplete_event_size limits buffered incomplete inbound data. Passing None uses the crate default.

Source

pub fn get_states(&self) -> HashMap<Role, State>

Returns a cloned map of both role states.

Source

pub fn get_our_state(&self) -> State

Returns the current state for this endpoint.

Source

pub fn get_their_state(&self) -> State

Returns the current state for the peer endpoint.

Source

pub fn get_client_is_waiting_for_100_continue(&self) -> bool

Returns whether the client is waiting for a 100 Continue response.

Source

pub fn get_they_are_waiting_for_100_continue(&self) -> bool

Returns whether the peer is waiting for a 100 Continue response.

Source

pub fn start_next_cycle(&mut self) -> Result<(), ProtocolError>

Starts the next keep-alive request/response cycle.

This is valid only when both sides have completed the previous cycle and the state machine allows reuse.

Source

pub fn get_trailing_data(&self) -> (Vec<u8>, bool)

Returns bytes received after the current event stream paused.

The boolean indicates whether EOF has been received.

Source

pub fn receive_data(&mut self, data: &[u8]) -> Result<(), ProtocolError>

Feeds received bytes into the connection.

Passing an empty slice marks EOF. After EOF, passing more bytes is a local protocol error.

Source

pub fn next_event(&mut self) -> Result<Event, ProtocolError>

Returns the next inbound protocol event.

If more bytes are needed, returns Event::NeedData. If processing is paused behind a completed message or protocol switch, returns Event::Paused.

Source

pub fn send(&mut self, event: Event) -> Result<Option<Vec<u8>>, ProtocolError>

Serializes an outbound event and advances local state.

Returns Ok(Some(bytes)) for events that produce wire bytes and Ok(None) for Event::ConnectionClosed. Invalid local sequencing or invalid event contents return ProtocolError::LocalProtocolError.

Source

pub fn send_failed(&mut self)

Marks the local send side as errored after an external write failure.

Auto Trait Implementations§

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