Trait Transport
pub trait Transport:
Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn buffers(&mut self) -> &mut dyn Buffers;
fn transmit_output(
&mut self,
amount: usize,
timeout: NextTimeout,
) -> Result<(), Error> ⓘ;
fn await_input(&mut self, timeout: NextTimeout) -> Result<bool, Error> ⓘ;
fn is_open(&mut self) -> bool;
// Provided method
fn is_tls(&self) -> bool { ... }
}
dep_ureq
only.Expand description
Transport of HTTP/1.1 as created by a Connector
.
In ureq, Transport
and Buffers
go hand in hand. The rest of ureq tries to minimize
the allocations, and the transport is responsible for providing the buffers required
to perform the request. Unless the transport requires special buffer handling, the
LazyBuffers
implementation can be used.
For sending data, the order of calls are:
Transport::buffers()
to obtain the buffers.Buffers::output()
orBuffers::tmp_and_output
depending where in the life cycle of the request ureq is.Transport::transmit_output()
to ask the transport to send/flush theamount
of buffers used in 2.
For receiving data, the order of calls are:
Transport::await_input()
- The transport impl itself uses
Buffers::input_append_buf()
to fill a number of bytes from the underlying transport and useBuffers::input_appended()
to tell the buffer how much been filled. Transport::buffers()
to obtain the buffersBuffers::input()
followed byBuffers::input_consume()
. It’s important to retain the unconsumed bytes for the next call toawait_input()
. This is handled byLazyBuffers
. It’s important to callBuffers::input_consume()
also with 0 consumed bytes since that’s how we keep track of whether the input is making progress.
Required Methods§
fn transmit_output(
&mut self,
amount: usize,
timeout: NextTimeout,
) -> Result<(), Error> ⓘ
fn transmit_output( &mut self, amount: usize, timeout: NextTimeout, ) -> Result<(), Error> ⓘ
Transmit amount
of the output buffer. ureq will always transmit the entirety
of the data written to the output buffer. It is expected that the transport will
transmit the entire requested amount
.
The timeout should be used to abort the transmission if the amount can’t be written in time.
If that happens the transport must return an Error::Timeout
instance.
fn await_input(&mut self, timeout: NextTimeout) -> Result<bool, Error> ⓘ
fn await_input(&mut self, timeout: NextTimeout) -> Result<bool, Error> ⓘ
Await input from the transport. The transport should internally use
Buffers::input_append_buf()
followed by Buffers::input_appended()
to
store the incoming data.