Connection

Struct Connection 

Source
pub struct Connection<T, S>{ /* private fields */ }
Expand description

A Future representing an HTTP/1 connection, bound to a Service, returned from Builder::serve_connection.

To drive HTTP on this connection this future must be polled, typically with .await. If it isn’t polled, no progress will be made on this connection.

Implementations§

Source§

impl<I, B, S> Connection<I, S>
where S: HttpService<Incoming, ResBody = B>, S::Error: Into<Box<dyn StdError + Send + Sync>>, I: Read + Write + Unpin, B: Body + 'static, B::Error: Into<Box<dyn StdError + Send + Sync>>,

Source

pub fn graceful_shutdown(self: Pin<&mut Self>)

Start a graceful shutdown process for this connection.

This Connection should continue to be polled until shutdown can finish.

§Note

This should only be called while the Connection future is still pending. If called after Connection::poll has resolved, this does nothing.

Source

pub fn into_parts(self) -> Parts<I, S>

Return the inner IO object, and additional information.

If the IO object has been “rewound” the io will not contain those bytes rewound. This should only be called after poll_without_shutdown signals that the connection is “done”. Otherwise, it may not have finished flushing all necessary HTTP bytes.

§Panics

This method will panic if this connection is using an h2 protocol.

Source

pub fn poll_without_shutdown( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<()>>
where S: Unpin, S::Future: Unpin,

Poll the connection for completion, but without calling shutdown on the underlying IO.

This is useful to allow running a connection while doing an HTTP upgrade. Once the upgrade is completed, the connection would be “done”, but it is not desired to actually shutdown the IO object. Instead you would take it back using into_parts.

Source

pub fn without_shutdown(self) -> impl Future<Output = Result<Parts<I, S>>>

Prevent shutdown of the underlying IO object at the end of service the request, instead run into_parts. This is a convenience wrapper over poll_without_shutdown.

§Error

This errors if the underlying connection protocol is not HTTP/1.

Source

pub fn with_upgrades(self) -> UpgradeableConnection<I, S>
where I: Send,

Enable this connection to support higher-level HTTP upgrades.

See the upgrade module for more.

Trait Implementations§

Source§

impl<I, S> Debug for Connection<I, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I, B, S> Future for Connection<I, S>
where S: HttpService<Incoming, ResBody = B>, S::Error: Into<Box<dyn StdError + Send + Sync>>, I: Read + Write + Unpin, B: Body + 'static, B::Error: Into<Box<dyn StdError + Send + Sync>>,

Source§

type Output = Result<(), Error>

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more
Source§

impl<'__pin, T, S> Unpin for Connection<T, S>
where PinnedFieldsOf<__Origin<'__pin, T, S>>: Unpin, S: HttpService<IncomingBody>,

Auto Trait Implementations§

§

impl<T, S> Freeze for Connection<T, S>
where S: Freeze, T: Freeze,

§

impl<T, S> !RefUnwindSafe for Connection<T, S>

§

impl<T, S> Send for Connection<T, S>

§

impl<T, S> Sync for Connection<T, S>

§

impl<T, S> !UnwindSafe for Connection<T, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<F, T, E> TryFuture for F
where F: Future<Output = Result<T, E>> + ?Sized,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

type Error = E

The type of failures yielded by this future
Source§

fn try_poll( self: Pin<&mut F>, cx: &mut Context<'_>, ) -> Poll<<F as Future>::Output>

Poll this TryFuture as if it were a Future. Read more
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.