pub struct UpgradedStream { /* private fields */ }Expand description
An owned post-HTTP IO handle for upgraded connections (101, CONNECT).
After Hyper transfers ownership of the underlying IO through its upgrade mechanism, this type owns the raw stream and provides async read/write, TLS upgrade, and metadata access.
§Ownership rules
- Once created, the connection is removed from the HTTP pool and must never be reused.
close()is idempotent.- Cancellation during
start_tls()closes or leaves the stream in a deterministic state.
Implementations§
Source§impl UpgradedStream
impl UpgradedStream
Sourcepub fn from_tcp(stream: TcpStream, leading_data: Bytes) -> Self
pub fn from_tcp(stream: TcpStream, leading_data: Bytes) -> Self
Wrap a tokio TCP stream into an upgraded stream.
Leading data is bytes already read from the connection before
the upgrade handshake completed (preserved by Hyper in its
Upgraded::read_buf).
Sourcepub fn from_tls(
stream: TlsStream<TcpStream>,
leading_data: Bytes,
tls_info: TlsInfo,
) -> Self
pub fn from_tls( stream: TlsStream<TcpStream>, leading_data: Bytes, tls_info: TlsInfo, ) -> Self
Wrap a TLS stream into an upgraded stream.
Sourcepub fn metadata(&self) -> &Arc<ConnectionMetadata> ⓘ
pub fn metadata(&self) -> &Arc<ConnectionMetadata> ⓘ
Returns a reference to the connection metadata.
Sourcepub fn variant(&self) -> UpgradedStreamVariant
pub fn variant(&self) -> UpgradedStreamVariant
Returns the concrete variant of the inner stream.
The Python bindings use this to refuse start_tls on streams
backed by Hyper’s opaque adapter (where the underlying TCP socket
is not recoverable).
Sourcepub fn leading_data(&self) -> &Bytes
pub fn leading_data(&self) -> &Bytes
Returns the leading data that was buffered before the upgrade.
These are bytes already read from the connection after the HTTP response headers but before the caller consumed the upgrade. They must be returned before any new socket reads.
Sourcepub fn take_leading_data(&mut self) -> Bytes
pub fn take_leading_data(&mut self) -> Bytes
Consume leading data, returning it.
Sourcepub async fn read(&mut self, max_bytes: usize) -> Result<Bytes>
pub async fn read(&mut self, max_bytes: usize) -> Result<Bytes>
Read up to max_bytes from the stream.
Returns the bytes read. Returns empty bytes on EOF.
§Errors
Returns Error::Io if the underlying read fails.
Sourcepub async fn close(&mut self) -> Result<()>
pub async fn close(&mut self) -> Result<()>
Shut down the stream (idempotent).
§Errors
This method currently always succeeds; errors are silently discarded to maintain idempotent close semantics.
Sourcepub async fn start_tls(
self,
tls_connector: &TlsConnector,
server_name: &str,
) -> Result<Self>
pub async fn start_tls( self, tls_connector: &TlsConnector, server_name: &str, ) -> Result<Self>
Upgrade this TCP stream to TLS.
Wraps the inner TCP stream with a new TLS layer using the
provided connector and server name. On success, returns a new
UpgradedStream with TLS metadata. The stream is consumed whether
the handshake succeeds or fails; callers that need a fallback must
retain their own connection before calling this method.
Only works for streams backed by a concrete TcpStream.
Adapter-based streams (from Hyper’s Upgraded) return an error
because the concrete type cannot be recovered.
§Errors
Returns Error::Tls if the handshake fails or the stream type
does not support TLS upgrade.
Trait Implementations§
Source§impl AsyncRead for UpgradedStream
impl AsyncRead for UpgradedStream
Source§impl AsyncWrite for UpgradedStream
impl AsyncWrite for UpgradedStream
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>],
) -> Poll<Result<usize, Error>>
fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>
poll_write, except that it writes from a slice of buffers. Read moreSource§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
poll_write_vectored
implementation. Read moreAuto Trait Implementations§
impl !Freeze for UpgradedStream
impl !RefUnwindSafe for UpgradedStream
impl !Sync for UpgradedStream
impl !UnwindSafe for UpgradedStream
impl Send for UpgradedStream
impl Unpin for UpgradedStream
impl UnsafeUnpin for UpgradedStream
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
Source§fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf. Read moreSource§fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
Source§fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
Source§fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
Source§fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
Source§fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
Source§fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
Source§fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
Source§fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
Source§fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
Source§fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
Source§fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
Source§fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
Source§fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
Source§fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
Source§fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
Source§fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
Source§fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
Source§fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
Source§fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
Source§fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
Source§fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
Source§fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
Source§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
buf. Read more