pub struct Session { /* private fields */ }Expand description
A single HTTP(S) connection in progress.
Implementations§
Source§impl Session
impl Session
Sourcepub fn plain(cfg: SessionConfig) -> Session
pub fn plain(cfg: SessionConfig) -> Session
Create a plaintext (HTTP/1.x) session.
Sourcepub fn tls(cfg: SessionConfig, stream: TlsStream) -> Session
pub fn tls(cfg: SessionConfig, stream: TlsStream) -> Session
Create a TLS (HTTPS) session wrapping an accepted
TlsStream. The protocol (HTTP/1.1 or HTTP/2)
is chosen once ALPN is known.
Sourcepub fn set_addrs(&mut self, peer: Option<SocketAddr>, local: Option<SocketAddr>)
pub fn set_addrs(&mut self, peer: Option<SocketAddr>, local: Option<SocketAddr>)
Record the connection’s peer and local socket addresses, reported to
handlers through Request::conn. The bundled runtimes call this for
every connection; a custom driver should call it right after creating
the session.
Sourcepub fn set_waker(&mut self, waker: impl Fn() + Send + Sync + 'static)
pub fn set_waker(&mut self, waker: impl Fn() + Send + Sync + 'static)
Register a callback fired whenever a stream response body
(Body::channel) has new data or ends. It runs
on the producer’s thread, so it should only wake the driver (signal a
condvar, a mio::Waker, a tokio Notify, …), which then calls
to_send and writes the result. Without a waker a
driver must poll to_send while is_streaming
is true.
Sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
Whether a response is streaming a body whose producer hasn’t finished:
more output may appear without any input from the peer. While this is
true, to_send returning nothing just means “not yet”.
Sourcepub fn received(&mut self, wire_in: &[u8]) -> Result<()>
pub fn received(&mut self, wire_in: &[u8]) -> Result<()>
Feed bytes received from the socket: decrypt, (lazily) select the protocol, parse requests, run the handler, and queue responses.
Sourcepub fn to_send(&mut self) -> Result<Vec<u8>>
pub fn to_send(&mut self) -> Result<Vec<u8>>
Produce the bytes to write to the socket: TLS handshake records and/or (encrypted) response data. May be empty.
Sourcepub fn has_output(&self) -> bool
pub fn has_output(&self) -> bool
Whether the engine still has output to produce — queued bytes or a
response body (e.g. a file) being streamed in chunks. Drivers must keep
calling to_send while this is true before waiting for
the next read or closing, so a body is flushed in full. (For a stream
body that is waiting on its producer, to_send returns nothing; see
is_streaming.)
Sourcepub fn wants_close(&self) -> bool
pub fn wants_close(&self) -> bool
Whether the connection should be closed once pending output is written.
Sourcepub fn handshaking(&self) -> bool
pub fn handshaking(&self) -> bool
Whether the session is still completing the TLS handshake.