Struct solicit::http::connection::HttpConnection
[−]
[src]
pub struct HttpConnection<S, R> where S: SendFrame, R: ReceiveFrame {
pub receiver: R,
pub sender: S,
pub scheme: HttpScheme,
// some fields omitted
}
The struct implements the HTTP/2 connection level logic.
This means that the struct is a bridge between the low level raw frame reads/writes (i.e. what
the SendFrame
and ReceiveFrame
traits do) and the higher session-level logic.
Therefore, it provides an API that exposes higher-level write operations, such as writing headers or data, that take care of all the underlying frame construction that is required.
Similarly, it provides an API for handling events that arise from receiving frames, without requiring the higher level to directly look at the frames themselves, rather only the semantic content within the frames.
Fields
receiver: R
The instance handling the reading of frames.
sender: S
The instance handling the writing of frames.
scheme: HttpScheme
The scheme of the connection
Methods
impl<S, R> HttpConnection<S, R> where S: SendFrame, R: ReceiveFrame
[src]
fn new(sender: S, receiver: R, scheme: HttpScheme) -> HttpConnection<S, R>
Creates a new HttpConnection
that will use the given sender and receiver instances
for writing and reading frames, respectively.
fn with_stream<TS>(stream: TS, scheme: HttpScheme) -> HttpConnection<TS, TS> where TS: TransportStream
Creates a new HttpConnection
that will use the given stream as its
underlying transport layer.
This constructor is provided as a convenience when the underlying IO of the
HTTP/2 connection should be based on the TransportStream
interface.
The scheme of the connection is also provided.
fn send_headers<H: Into<Vec<Header>>>(&mut self, headers: H, stream_id: StreamId, end_stream: EndStream) -> HttpResult<()>
A helper function that inserts the frames required to send the given headers onto the
SendFrame
stream.
The HttpConnection
performs the HPACK encoding of the header block using an internal
encoder.
Parameters
headers
- a headers list that should be sent.stream_id
- the ID of the stream on which the headers will be sent. The connection performs no checks as to whether the stream is a valid identifier.end_stream
- whether the stream should be closed from the peer's side immediately after sending the headers
fn send_data<'a>(&mut self, chunk: DataChunk<'a>) -> HttpResult<()>
A helper function that inserts a frame representing the given data into the SendFrame
stream.
The HttpConnection
itself does not track the flow control window and will happily send
data that exceeds a particular stream's or the connection's flow control window size.
Parameters
data
- the data that should be sent on the connectionstream_id
- the ID of the stream on which the data will be sentend_stream
- whether the stream should be closed from the peer's side immediately after sending the data (i.e. the last data frame closes the stream).
fn send_next_data<P: DataPrioritizer>(&mut self, prioritizer: &mut P) -> HttpResult<SendStatus>
Sends the chunk of data provided by the given DataPrioritizer
.
Returns
Returns the status of the operation. If the provider does not currently have any data that
could be sent, returns SendStatus::Nothing
. If any data is sent, returns
SendStatus::Sent
.
fn expect_settings<Sess: Session>(&mut self, session: &mut Sess) -> HttpResult<()>
The method processes the next incoming frame, expecting it to be a SETTINGS frame. Additionally, the frame cannot be an ACK settings frame, but rather it should contain the peer's settings.
The method can be used when the receipt of the peer's preface needs to be asserted.
If the received frame is not a SETTINGS frame, an HttpError::UnableToConnect
variant is
returned. (TODO: Change this variant's name, as it is a byproduct of this method's legacy)
fn handle_next_frame<Sess: Session>(&mut self, session: &mut Sess) -> HttpResult<()>
Handles the next frame incoming on the ReceiveFrame
instance.
The HttpConnection
takes care of parsing the frame and extracting the semantics behind it
and passes this on to the higher level by invoking (possibly multiple) callbacks on the
given Session
instance. For information on which events can be passed to the session,
check out the Session
trait.
If the handling is successful, a unit Ok
is returned; all HTTP and IO errors are
propagated.