pub enum HttpSession {
H1(HttpSession),
H2(Http2Session),
}
Expand description
A type for Http client session. It can be either an Http1 connection or an Http2 stream.
Variants§
H1(HttpSession)
H2(Http2Session)
Implementations§
Source§impl HttpSession
impl HttpSession
pub fn as_http1(&self) -> Option<&Http1Session>
pub fn as_http2(&self) -> Option<&Http2Session>
Sourcepub async fn write_request_header(
&mut self,
req: Box<RequestHeader>,
) -> Result<()>
pub async fn write_request_header( &mut self, req: Box<RequestHeader>, ) -> Result<()>
Write the request header to the server After the request header is sent. The caller can either start reading the response or sending request body if any.
Sourcepub async fn write_request_body(&mut self, data: Bytes, end: bool) -> Result<()>
pub async fn write_request_body(&mut self, data: Bytes, end: bool) -> Result<()>
Write a chunk of the request body.
Sourcepub async fn finish_request_body(&mut self) -> Result<()>
pub async fn finish_request_body(&mut self) -> Result<()>
Signal that the request body has ended
Sourcepub fn set_read_timeout(&mut self, timeout: Duration)
pub fn set_read_timeout(&mut self, timeout: Duration)
Set the read timeout for reading header and body.
The timeout is per read operation, not on the overall time reading the entire response
Sourcepub fn set_write_timeout(&mut self, timeout: Duration)
pub fn set_write_timeout(&mut self, timeout: Duration)
Set the write timeout for writing header and body.
The timeout is per write operation, not on the overall time writing the entire request.
This is a noop for h2.
Sourcepub async fn read_response_header(&mut self) -> Result<()>
pub async fn read_response_header(&mut self) -> Result<()>
Read the response header from the server For http1, this function can be called multiple times, if the headers received are just informational headers.
Sourcepub async fn read_response_body(&mut self) -> Result<Option<Bytes>>
pub async fn read_response_body(&mut self) -> Result<Option<Bytes>>
Read response body
None
when no more body to read.
Sourcepub fn response_done(&mut self) -> bool
pub fn response_done(&mut self) -> bool
No (more) body to read
Sourcepub async fn shutdown(&mut self)
pub async fn shutdown(&mut self)
Give up the http session abruptly. For H1 this will close the underlying connection For H2 this will send RST_STREAM frame to end this stream if the stream has not ended at all
Sourcepub fn response_header(&self) -> Option<&ResponseHeader>
pub fn response_header(&self) -> Option<&ResponseHeader>
Get the response header of the server
None
if the response header is not read yet.
Sourcepub fn digest(&self) -> Option<&Digest>
pub fn digest(&self) -> Option<&Digest>
Return the Digest of the connection
For reused connection, the timing in the digest will reflect its initial handshakes The caller should check if the connection is reused to avoid misuse of the timing field.
Sourcepub fn digest_mut(&mut self) -> Option<&mut Digest>
pub fn digest_mut(&mut self) -> Option<&mut Digest>
Return a mutable Digest reference for the connection.
Will return None
if this is an H2 session and multiple streams are open.
Sourcepub fn server_addr(&self) -> Option<&SocketAddr>
pub fn server_addr(&self) -> Option<&SocketAddr>
Return the server (peer) address of the connection.
Sourcepub fn client_addr(&self) -> Option<&SocketAddr>
pub fn client_addr(&self) -> Option<&SocketAddr>
Return the client (local) address of the connection.