Struct HyperHttpConnection

Source
pub struct HyperHttpConnection { /* private fields */ }
Expand description

An HTTP connection using the Hyper library and Tokio runtime.

HyperHttpConnection wraps a synchronous-style API on top of an async hyper client, implementing the embedded_svc::http::client::Connection trait.

§Example

use embedded_svc::http::client::Client;
use native_svc::HyperHttpConnection;

let conn = HyperHttpConnection::new().unwrap();
let mut client = Client::wrap(conn);
let mut request = client.get("https://example.com").unwrap();
let mut response = request.submit().unwrap();
// read, process, etc.

Implementations§

Source§

impl HyperHttpConnection

Source

pub fn new() -> Result<Self, HyperError>

Creates a new HyperHttpConnection instance.

Initializes a Tokio runtime, a TLS-enabled Hyper client, and prepares internal buffers. Returns an error if the runtime cannot be created.

Trait Implementations§

Source§

impl Connection for HyperHttpConnection

Source§

fn initiate_request<'a>( &'a mut self, method: Method, uri: &'a str, headers: &'a [(&'a str, &'a str)], ) -> Result<(), Self::Error>

Begins constructing an HTTP request with method, URI, and headers.

Source§

fn is_request_initiated(&self) -> bool

Returns true if a request has been initiated.

Source§

fn initiate_response(&mut self) -> Result<(), Self::Error>

Sends the initiated request and stores the response.

Source§

fn is_response_initiated(&self) -> bool

Returns true if a response has been received.

Source§

fn split(&mut self) -> (&Self::Headers, &mut Self::Read)

Splits the connection into its header and body parts.

Source§

fn raw_connection(&mut self) -> Result<&mut Self::RawConnection, Self::Error>

Returns a mutable reference to the raw connection.

Source§

type Headers = HyperHttpConnection

Source§

type Read = HyperHttpConnection

Source§

type RawConnectionError = HyperError

Source§

type RawConnection = HyperHttpConnection

Source§

impl Default for HyperHttpConnection

Source§

fn default() -> Self

Provides a default instance, panicking on failure.

Equivalent to calling HyperHttpConnection::new().unwrap().

Source§

impl ErrorType for HyperHttpConnection

Source§

type Error = HyperError

The error type returned by this connection.

Source§

impl Headers for HyperHttpConnection

Source§

fn header(&self, name: &str) -> Option<&str>

Retrieves a header value by name from the last response, if set.

Source§

fn content_type(&self) -> Option<&str>

Source§

fn content_len(&self) -> Option<u64>

Source§

fn content_encoding(&self) -> Option<&str>

Source§

fn transfer_encoding(&self) -> Option<&str>

Source§

fn host(&self) -> Option<&str>

Source§

fn connection(&self) -> Option<&str>

Source§

fn cache_control(&self) -> Option<&str>

Source§

fn upgrade(&self) -> Option<&str>

Source§

impl Read for HyperHttpConnection

Source§

fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Self::Error>

Reads data from the internal buffer, loading the response body if needed. Returns Ok(0) on EOF.

Source§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

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

impl Status for HyperHttpConnection

Source§

fn status(&self) -> u16

Returns the HTTP status code of the last response, or 500 if none.

Source§

fn status_message(&self) -> Option<&str>

Returns the reason phrase of the last response status, if available.

Source§

impl Write for HyperHttpConnection

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize, HyperError>

Buffers data to be sent in the request body.

Source§

fn flush(&mut self) -> Result<(), HyperError>

Finalizes the request body by replacing it with the buffered data.

Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more
Source§

fn write_fmt( &mut self, fmt: Arguments<'_>, ) -> Result<(), WriteFmtError<Self::Error>>

Write a formatted string into this writer, returning any error encountered. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more