[][src]Struct aahc::SendBody

pub struct SendBody<'socket, Socket: AsyncWrite + ?Sized> { /* fields omitted */ }

An in-progress HTTP request which is currently sending a request body.

After the headers are sent, an instance of this type is obtained. It implements AsyncWrite, which allows the application to write the request body. When the request body is finished (or immediately, if there is no request body to send), finish should be called to proceed to the next step.

The 'socket lifetime parameter is the lifetime of the transport socket. The Socket type parameter is the type of transport-layer socket over which the HTTP request will be sent.

Implementations

impl<'socket, Socket: AsyncWrite + ?Sized> Send<'socket, Socket>[src]

pub fn hint_length(&mut self, length: u64)[src]

Gives a hint about how many bytes of body remain to be sent.

The length parameter is the minimum number of bytes of body that will be sent from this point forward.

The application must send at least length bytes before finishing the request. However, it is permitted to send more than length bytes (subject to any other constraints, such as not sending more than specified in the content-length header).

For a fixed-length request (e.g. one whose length was set by a content-length header), this function does nothing.

For a chunked request, this function sets the size of the next chunk; this allows a large chunk size to be sent without the entire contents of the chunk needing to be available at once. For example, if the application knows that the body will contain at least another 100,000 bytes, it could call this function passing a length parameter of 100,000, but then write just 10,000 bytes at a time, ten times over. Without calling this function, that would result in ten 10,000-byte chunks being sent; by calling this function, a single 100,000-byte chunk is sent instead, reducing the overhead due to chunk headers, without requiring that the application load all 100,000 bytes into memory at once.

pub async fn finish(self) -> Result<Metadata>[src]

Finishes the request.

On success, a metadata instance is returned. This instance must be passed in when the application is ready to receive the response headers.

Important: This function does not flush the socket. If the application is going to read a response, or if the socket is a buffered wrapper around an underlying socket and the application intends to unwrap the wrapper, it must flush the socket before proceeding to read the response, otherwise a hang might occur due to the server waiting for the remainder of the request which will never arrive. If the application intends to send another request instead, using HTTP pipelining, the flush is not necessary.

Errors

This function returns an error if writing to the underlying socket fails.

Panics

This function panics in a debug build:

  • if the body has a fixed length and was not fully sent
  • if the body is chunked and the most recent chunk was not fully sent

These are debug-build panics, not errors, because it is expected that the application will provide a request body consistent with the request headers; since both of these things are under the application’s control, an inconsistency between them represents a bug in the application.

Trait Implementations

impl<Socket: AsyncWrite + ?Sized, '_> AsyncWrite for Send<'_, Socket>[src]

impl<'socket, Socket: Debug + AsyncWrite + ?Sized> Debug for Send<'socket, Socket>[src]

impl<'socket, Socket: Eq + AsyncWrite + ?Sized> Eq for Send<'socket, Socket>[src]

impl<'socket, Socket: PartialEq + AsyncWrite + ?Sized> PartialEq<Send<'socket, Socket>> for Send<'socket, Socket>[src]

impl<'socket, Socket: AsyncWrite + ?Sized> StructuralEq for Send<'socket, Socket>[src]

impl<'socket, Socket: AsyncWrite + ?Sized> StructuralPartialEq for Send<'socket, Socket>[src]

Auto Trait Implementations

impl<'socket, Socket: ?Sized> RefUnwindSafe for Send<'socket, Socket> where
    Socket: RefUnwindSafe

impl<'socket, Socket: ?Sized> Send for Send<'socket, Socket> where
    Socket: Send

impl<'socket, Socket: ?Sized> Sync for Send<'socket, Socket> where
    Socket: Sync

impl<'socket, Socket: ?Sized> Unpin for Send<'socket, Socket>

impl<'socket, Socket> !UnwindSafe for Send<'socket, Socket>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.