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 { ... }
}
Available on crate feature 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:

  1. Transport::buffers() to obtain the buffers.
  2. Buffers::output() or Buffers::tmp_and_output depending where in the life cycle of the request ureq is.
  3. Transport::transmit_output() to ask the transport to send/flush the amount of buffers used in 2.

For receiving data, the order of calls are:

  1. Transport::await_input()
  2. The transport impl itself uses Buffers::input_append_buf() to fill a number of bytes from the underlying transport and use Buffers::input_appended() to tell the buffer how much been filled.
  3. Transport::buffers() to obtain the buffers
  4. Buffers::input() followed by Buffers::input_consume(). It’s important to retain the unconsumed bytes for the next call to await_input(). This is handled by LazyBuffers. It’s important to call Buffers::input_consume() also with 0 consumed bytes since that’s how we keep track of whether the input is making progress.

Required Methods§

fn buffers(&mut self) -> &mut dyn Buffers

Provide buffers for this transport.

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>

Await input from the transport. The transport should internally use Buffers::input_append_buf() followed by Buffers::input_appended() to store the incoming data.

fn is_open(&mut self) -> bool

Tell whether this transport is still functional. This must provide an accurate answer for connection pooling to work.

Provided Methods§

fn is_tls(&self) -> bool

Whether the transport is TLS.

Defaults to false, override in TLS transports.

Implementations on Foreign Types§

§

impl Transport for ()

§

fn buffers(&mut self) -> &mut dyn Buffers

§

fn transmit_output(&mut self, _: usize, _: NextTimeout) -> Result<(), Error>

§

fn await_input(&mut self, _: NextTimeout) -> Result<bool, Error>

§

fn is_open(&mut self) -> bool

Implementors§

§

impl<A, B> Transport for Either<A, B>
where A: Transport, B: Transport,

§

impl<T> Transport for Box<T>
where T: Transport + ?Sized,