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: RoleRole represented by this connection object.
their_role: RolePeer role.
their_http_version: Option<Vec<u8>>Most recently observed peer HTTP version, without the HTTP/ prefix.
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn new(our_role: Role, max_incomplete_event_size: Option<usize>) -> Self
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.
Sourcepub fn get_states(&self) -> HashMap<Role, State>
pub fn get_states(&self) -> HashMap<Role, State>
Returns a cloned map of both role states.
Sourcepub fn get_our_state(&self) -> State
pub fn get_our_state(&self) -> State
Returns the current state for this endpoint.
Sourcepub fn get_their_state(&self) -> State
pub fn get_their_state(&self) -> State
Returns the current state for the peer endpoint.
Sourcepub fn get_client_is_waiting_for_100_continue(&self) -> bool
pub fn get_client_is_waiting_for_100_continue(&self) -> bool
Returns whether the client is waiting for a 100 Continue response.
Sourcepub fn get_they_are_waiting_for_100_continue(&self) -> bool
pub fn get_they_are_waiting_for_100_continue(&self) -> bool
Returns whether the peer is waiting for a 100 Continue response.
Sourcepub fn start_next_cycle(&mut self) -> Result<(), ProtocolError>
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.
Sourcepub fn get_trailing_data(&self) -> (Vec<u8>, bool)
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.
Sourcepub fn receive_data(&mut self, data: &[u8]) -> Result<(), ProtocolError>
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.
Sourcepub fn next_event(&mut self) -> Result<Event, ProtocolError>
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.
Sourcepub fn send(&mut self, event: Event) -> Result<Option<Vec<u8>>, ProtocolError>
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.
Sourcepub fn send_failed(&mut self)
pub fn send_failed(&mut self)
Marks the local send side as errored after an external write failure.