Skip to main content

Upgrade

Struct Upgrade 

Source
pub struct Upgrade<Transport> { /* private fields */ }
Expand description

An HTTP upgrade — owns the underlying transport along with all the data from the originating Conn.

Reading the transport directly: drain buffer first if it has bytes in it. Reading via the AsyncRead impl on Upgrade handles this automatically.

Implementations§

Source§

impl<Transport> Upgrade<Transport>

Source

pub fn received_headers(&self) -> &Headers

Borrows The http headers the peer sent to us

Source

pub fn request_headers(&self) -> &Headers

👎Deprecated since 1.3.0:

use received_headers instead

Borrows The http headers the peer sent to us

Source

pub fn received_headers_mut(&mut self) -> &mut Headers

Mutably borrow The http headers the peer sent to us

Source

pub fn request_headers_mut(&mut self) -> &mut Headers

👎Deprecated since 1.3.0:

use received_headers_mut instead

Mutably borrow The http headers the peer sent to us

Source

pub fn set_received_headers(&mut self, received_headers: Headers) -> &mut Self

Sets The http headers the peer sent to us, returning &mut Self for chaining

Source

pub fn set_request_headers(&mut self, request_headers: Headers) -> &mut Self

👎Deprecated since 1.3.0:

use set_received_headers instead

Sets The http headers the peer sent to us, returning &mut Self for chaining

Source

pub fn with_received_headers(self, received_headers: Headers) -> Self

Owned chainable setter for The http headers the peer sent to us, returning Self

Source

pub fn with_request_headers(self, request_headers: Headers) -> Self

👎Deprecated since 1.3.0:

use with_received_headers instead

Owned chainable setter for The http headers the peer sent to us, returning Self

Source

pub fn into_received_headers(self) -> Headers

Consumes self, returning The http headers the peer sent to us

Source

pub fn into_request_headers(self) -> Headers

👎Deprecated since 1.3.0:

use into_received_headers instead

Consumes self, returning The http headers the peer sent to us

Source

pub fn sent_headers(&self) -> &Headers

Borrows The http headers as set before the upgrade was negotiated and sent to the peer.

Source

pub fn response_headers(&self) -> &Headers

👎Deprecated since 1.3.0:

use sent_headers instead

Borrows The http headers as set before the upgrade was negotiated and sent to the peer.

Source

pub fn sent_headers_mut(&mut self) -> &mut Headers

Mutably borrow The http headers as set before the upgrade was negotiated and sent to the peer.

Source

pub fn response_headers_mut(&mut self) -> &mut Headers

👎Deprecated since 1.3.0:

use sent_headers_mut instead

Mutably borrow The http headers as set before the upgrade was negotiated and sent to the peer.

Source

pub fn set_sent_headers(&mut self, sent_headers: Headers) -> &mut Self

Sets The http headers as set before the upgrade was negotiated and sent, returning &mut Self for chaining to the peer.

Source

pub fn set_response_headers(&mut self, response_headers: Headers) -> &mut Self

👎Deprecated since 1.3.0:

use set_sent_headers instead

Sets The http headers as set before the upgrade was negotiated and sent, returning &mut Self for chaining to the peer.

Source

pub fn with_sent_headers(self, sent_headers: Headers) -> Self

Owned chainable setter for The http headers as set before the upgrade was negotiated and sent, returning Self to the peer.

Source

pub fn with_response_headers(self, response_headers: Headers) -> Self

👎Deprecated since 1.3.0:

use with_sent_headers instead

Owned chainable setter for The http headers as set before the upgrade was negotiated and sent, returning Self to the peer.

Source

pub fn into_sent_headers(self) -> Headers

Consumes self, returning The http headers as set before the upgrade was negotiated and sent to the peer.

Source

pub fn into_response_headers(self) -> Headers

👎Deprecated since 1.3.0:

use into_sent_headers instead

Consumes self, returning The http headers as set before the upgrade was negotiated and sent to the peer.

Source

pub fn path_mut(&mut self) -> &mut Cow<'static, str>

Mutably borrow The request path

Source

pub fn set_path(&mut self, path: Cow<'static, str>) -> &mut Self

Sets The request path, returning &mut Self for chaining

Source

pub fn with_path(self, path: Cow<'static, str>) -> Self

Owned chainable setter for The request path, returning Self

Source

pub fn into_path(self) -> Cow<'static, str>

Consumes self, returning The request path

Source

pub fn method(&self) -> Method

Returns a copy of The http request method

Source

pub fn method_mut(&mut self) -> &mut Method

Mutably borrow The http request method

Source

pub fn set_method(&mut self, method: Method) -> &mut Self

Sets The http request method, returning &mut Self for chaining

Source

pub fn with_method(self, method: Method) -> Self

Owned chainable setter for The http request method, returning Self

Source

pub fn state(&self) -> &TypeSet

Borrows Any state that has been accumulated on the Conn before negotiating the upgrade

Source

pub fn state_mut(&mut self) -> &mut TypeSet

Mutably borrow Any state that has been accumulated on the Conn before negotiating the upgrade

Source

pub fn set_state(&mut self, state: TypeSet) -> &mut Self

Sets Any state that has been accumulated on the Conn before negotiating the upgrade, returning &mut Self for chaining

Source

pub fn with_state(self, state: TypeSet) -> Self

Owned chainable setter for Any state that has been accumulated on the Conn before negotiating the upgrade, returning Self

Source

pub fn into_state(self) -> TypeSet

Consumes self, returning Any state that has been accumulated on the Conn before negotiating the upgrade

Source

pub fn transport(&self) -> &Transport

Borrows The underlying io (often a TcpStream or similar)

Source

pub fn transport_mut(&mut self) -> &mut Transport

Mutably borrow The underlying io (often a TcpStream or similar)

Source

pub fn set_transport(&mut self, transport: Transport) -> &mut Self

Sets The underlying io (often a TcpStream or similar), returning &mut Self for chaining

Source

pub fn with_transport(self, transport: Transport) -> Self

Owned chainable setter for The underlying io (often a TcpStream or similar), returning Self

Source

pub fn into_transport(self) -> Transport

Consumes self, returning The underlying io (often a TcpStream or similar)

Source

pub fn buffer(&self) -> &[u8]

Borrows Any bytes that have been read from the underlying transport already.

It is your responsibility to process these bytes before reading directly from the transport.

Source

pub fn buffer_mut(&mut self) -> &mut [u8]

Mutably borrow Any bytes that have been read from the underlying transport already.

It is your responsibility to process these bytes before reading directly from the transport.

Source

pub fn context(&self) -> &Arc<HttpContext>

Borrows The HttpContext shared for this server

Source

pub fn context_mut(&mut self) -> &mut Arc<HttpContext>

Mutably borrow The HttpContext shared for this server

Source

pub fn set_context(&mut self, context: Arc<HttpContext>) -> &mut Self

Sets The HttpContext shared for this server, returning &mut Self for chaining

Source

pub fn with_context(self, context: Arc<HttpContext>) -> Self

Owned chainable setter for The HttpContext shared for this server, returning Self

Source

pub fn into_context(self) -> Arc<HttpContext>

Consumes self, returning The HttpContext shared for this server

Source

pub fn peer_ip(&self) -> Option<IpAddr>

Returns a copy of the ip address of the connection, if available

Source

pub fn peer_ip_mut(&mut self) -> Option<&mut IpAddr>

Mutably borrow the ip address of the connection, if available

Source

pub fn set_peer_ip(&mut self, peer_ip: Option<IpAddr>) -> &mut Self

Sets the ip address of the connection, if available, returning &mut Self for chaining

Source

pub fn with_peer_ip(self, peer_ip: Option<IpAddr>) -> Self

Owned chainable setter for the ip address of the connection, if available, returning Self

Source

pub fn take_peer_ip(&mut self) -> Option<IpAddr>

Takes the ip address of the connection, if available, leaving a None in its place

Source

pub fn start_time(&self) -> Instant

Returns a copy of the wall-clock time at which the underlying Conn was constructed

Source

pub fn start_time_mut(&mut self) -> &mut Instant

Mutably borrow the wall-clock time at which the underlying Conn was constructed

Source

pub fn set_start_time(&mut self, start_time: Instant) -> &mut Self

Sets the wall-clock time at which the underlying Conn was constructed, returning &mut Self for chaining

Source

pub fn with_start_time(self, start_time: Instant) -> Self

Owned chainable setter for the wall-clock time at which the underlying Conn was constructed, returning Self

Source

pub fn authority(&self) -> Option<&str>

Borrows the :authority http/3 pseudo-header

Source

pub fn authority_mut(&mut self) -> Option<&mut Cow<'static, str>>

Mutably borrow the :authority http/3 pseudo-header

Source

pub fn set_authority( &mut self, authority: Option<Cow<'static, str>>, ) -> &mut Self

Sets the :authority http/3 pseudo-header, returning &mut Self for chaining

Source

pub fn with_authority(self, authority: Option<Cow<'static, str>>) -> Self

Owned chainable setter for the :authority http/3 pseudo-header, returning Self

Source

pub fn take_authority(&mut self) -> Option<Cow<'static, str>>

Takes the :authority http/3 pseudo-header, leaving a None in its place

Source

pub fn into_authority(self) -> Option<Cow<'static, str>>

Consumes self, returning the :authority http/3 pseudo-header

Source

pub fn scheme(&self) -> Option<&str>

Borrows the :scheme http/3 pseudo-header

Source

pub fn scheme_mut(&mut self) -> Option<&mut Cow<'static, str>>

Mutably borrow the :scheme http/3 pseudo-header

Source

pub fn set_scheme(&mut self, scheme: Option<Cow<'static, str>>) -> &mut Self

Sets the :scheme http/3 pseudo-header, returning &mut Self for chaining

Source

pub fn with_scheme(self, scheme: Option<Cow<'static, str>>) -> Self

Owned chainable setter for the :scheme http/3 pseudo-header, returning Self

Source

pub fn take_scheme(&mut self) -> Option<Cow<'static, str>>

Takes the :scheme http/3 pseudo-header, leaving a None in its place

Source

pub fn into_scheme(self) -> Option<Cow<'static, str>>

Consumes self, returning the :scheme http/3 pseudo-header

Source

pub fn protocol(&self) -> Option<&str>

Borrows the :protocol http/3 pseudo-header

Source

pub fn protocol_mut(&mut self) -> Option<&mut Cow<'static, str>>

Mutably borrow the :protocol http/3 pseudo-header

Source

pub fn set_protocol(&mut self, protocol: Option<Cow<'static, str>>) -> &mut Self

Sets the :protocol http/3 pseudo-header, returning &mut Self for chaining

Source

pub fn with_protocol(self, protocol: Option<Cow<'static, str>>) -> Self

Owned chainable setter for the :protocol http/3 pseudo-header, returning Self

Source

pub fn take_protocol(&mut self) -> Option<Cow<'static, str>>

Takes the :protocol http/3 pseudo-header, leaving a None in its place

Source

pub fn into_protocol(self) -> Option<Cow<'static, str>>

Consumes self, returning the :protocol http/3 pseudo-header

Source

pub fn http_version(&self) -> &Version

Borrows the http version

Source

pub fn http_version_mut(&mut self) -> &mut Version

Mutably borrow the http version

Source

pub fn set_http_version(&mut self, http_version: Version) -> &mut Self

Sets the http version, returning &mut Self for chaining

Source

pub fn with_http_version(self, http_version: Version) -> Self

Owned chainable setter for the http version, returning Self

Source

pub fn into_http_version(self) -> Version

Consumes self, returning the http version

Source

pub fn status(&self) -> Option<Status>

Returns a copy of the http response status set on the underlying Conn before the upgrade (typically 101 Switching Protocols, or 200 OK for CONNECT). None if unset.

Source

pub fn status_mut(&mut self) -> Option<&mut Status>

Mutably borrow the http response status set on the underlying Conn before the upgrade (typically 101 Switching Protocols, or 200 OK for CONNECT). None if unset.

Source

pub fn set_status(&mut self, status: Option<Status>) -> &mut Self

Sets the http response status set on the underlying Conn before the upgrade, returning &mut Self for chaining (typically 101 Switching Protocols, or 200 OK for CONNECT). None if unset.

Source

pub fn with_status(self, status: Option<Status>) -> Self

Owned chainable setter for the http response status set on the underlying Conn before the upgrade, returning Self (typically 101 Switching Protocols, or 200 OK for CONNECT). None if unset.

Source

pub fn take_status(&mut self) -> Option<Status>

Takes the http response status set on the underlying Conn before the upgrade, leaving a None in its place (typically 101 Switching Protocols, or 200 OK for CONNECT). None if unset.

Source

pub fn is_secure(&self) -> bool

Returns a copy of whether this connection was deemed secure by the handler stack

Source

pub fn secure_mut(&mut self) -> &mut bool

Mutably borrow whether this connection was deemed secure by the handler stack

Source

pub fn set_secure(&mut self, secure: bool) -> &mut Self

Sets whether this connection was deemed secure by the handler stack, returning &mut Self for chaining

Source

pub fn with_secure(self, secure: bool) -> Self

Owned chainable setter for whether this connection was deemed secure by the handler stack, returning Self

Source

pub fn received_trailers(&self) -> Option<&Headers>

Borrows Inbound trailers, populated either by a fully-consumed pre-upgrade body or by the post-upgrade inbound state machine. Some only when non-empty.

Source

pub fn received_trailers_mut(&mut self) -> Option<&mut Headers>

Mutably borrow Inbound trailers, populated either by a fully-consumed pre-upgrade body or by the post-upgrade inbound state machine. Some only when non-empty.

Source

pub fn take_received_trailers(&mut self) -> Option<Headers>

Takes Inbound trailers, populated either by a fully-consumed pre-upgrade body or by, leaving a None in its place the post-upgrade inbound state machine. Some only when non-empty.

Source§

impl<Transport> Upgrade<Transport>

Source

pub fn h2_connection(&self) -> Option<&Arc<H2Connection>>

the H2Connection driver for this upgrade, if it originated from an HTTP/2 stream

Source

pub fn h2_stream_id(&self) -> Option<u32>

the h2 stream id for this upgrade, if it originated from an HTTP/2 stream

Source

pub fn h3_connection(&self) -> Option<&Arc<H3Connection>>

the H3Connection driver for this upgrade, if it originated from an HTTP/3 stream

Source

pub fn h3_stream_id(&self) -> Option<u64>

the h3 stream id for this upgrade, if it originated from an HTTP/3 stream

Source

pub fn take_buffer(&mut self) -> Vec<u8>

Take any buffered bytes

Source

pub fn shared_state(&self) -> &TypeSet

borrow the shared state TypeSet for this application

Source

pub fn path(&self) -> &str

the http request path up to but excluding any query component

Source

pub fn querystring(&self) -> &str

retrieves the query component of the path

Source

pub fn map_transport<T: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static>( self, f: impl Fn(Transport) -> T, ) -> Upgrade<T>

Modify the transport type of this upgrade.

This is useful for boxing the transport in order to erase the type argument.

Source§

impl<Transport: AsyncWrite + Unpin> Upgrade<Transport>

Source

pub async fn send_trailers(self, trailers: Headers) -> Result<()>

Emit trailing headers and finish the outbound stream. Consumes self; further writes are statically prevented.

Per-protocol behavior:

  • HTTP/1.1 with Transfer-Encoding: chunked: writes the last-chunk marker (0\r\n), the trailer section, and a final CRLF, then closes the transport.
  • HTTP/2: enqueues a trailing HEADERS frame with END_STREAM via the connection driver and returns. The driver finishes the stream after draining any pending DATA frames.
  • HTTP/3: encodes a trailing HEADERS frame via QPACK, writes it to the stream, then closes the stream (QUIC FIN).
  • HTTP/1.1 without chunked encoding (raw upgrade, CONNECT tunnel, websocket-over-h1): trailers can’t be expressed on the wire; dropped with a log::warn! and Ok(()) returned.
§Errors

Returns the underlying io::Error when the wire write fails, BrokenPipe if the stream has already been closed, and NotConnected if the carried ProtocolSession is missing the expected driver for h2/h3.

Trait Implementations§

Source§

impl<Transport> AsyncRead for Upgrade<Transport>
where Transport: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,

Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into buf. Read more
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

impl<Transport: AsyncWrite + Unpin> AsyncWrite for Upgrade<Transport>

Source§

fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
Source§

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

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

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

Attempt to close the object. Read more
Source§

impl<Transport> Debug for Upgrade<Transport>

Source§

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

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

impl<Transport> From<Conn<Transport>> for Upgrade<Transport>

Source§

fn from(conn: Conn<Transport>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Transport> Freeze for Upgrade<Transport>
where Transport: Freeze,

§

impl<Transport> !RefUnwindSafe for Upgrade<Transport>

§

impl<Transport> Send for Upgrade<Transport>
where Transport: Send,

§

impl<Transport> Sync for Upgrade<Transport>
where Transport: Sync,

§

impl<Transport> Unpin for Upgrade<Transport>
where Transport: Unpin,

§

impl<Transport> UnsafeUnpin for Upgrade<Transport>
where Transport: UnsafeUnpin,

§

impl<Transport> !UnwindSafe for Upgrade<Transport>

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<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>
where Self: Unpin,

Reads some bytes from the byte stream. Read more
Source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>], ) -> ReadVectoredFuture<'a, Self>
where Self: Unpin,

Like read(), except it reads into a slice of buffers. Read more
Source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> ReadToEndFuture<'a, Self>
where Self: Unpin,

Reads the entire contents and appends them to a Vec. Read more
Source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String, ) -> ReadToStringFuture<'a, Self>
where Self: Unpin,

Reads the entire contents and appends them to a String. Read more
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>
where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Converts this AsyncRead into a Stream of bytes. Read more
Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: AsyncRead, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
Source§

fn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
Source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>
where Self: Unpin,

Writes some bytes into the byte stream. Read more
Source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], ) -> WriteVectoredFuture<'a, Self>
where Self: Unpin,

Like write(), except that it writes a slice of buffers. Read more
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>
where Self: Unpin,

Writes an entire buffer into the byte stream. Read more
Source§

fn flush(&mut self) -> FlushFuture<'_, Self>
where Self: Unpin,

Flushes the stream to ensure that all buffered contents reach their destination. Read more
Source§

fn close(&mut self) -> CloseFuture<'_, Self>
where Self: Unpin,

Closes the writer. Read more
Source§

fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. 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<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<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.