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
impl HyperHttpConnection
Sourcepub fn new() -> Result<Self, HyperError>
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
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>
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
fn is_request_initiated(&self) -> bool
Returns true
if a request has been initiated.
Source§fn initiate_response(&mut self) -> Result<(), Self::Error>
fn initiate_response(&mut self) -> Result<(), Self::Error>
Sends the initiated request and stores the response.
Source§fn is_response_initiated(&self) -> bool
fn is_response_initiated(&self) -> bool
Returns true
if a response has been received.
Source§fn split(&mut self) -> (&Self::Headers, &mut Self::Read)
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>
fn raw_connection(&mut self) -> Result<&mut Self::RawConnection, Self::Error>
Returns a mutable reference to the raw connection.
type Headers = HyperHttpConnection
type Read = HyperHttpConnection
type RawConnectionError = HyperError
type RawConnection = HyperHttpConnection
Source§impl Default for HyperHttpConnection
impl Default for HyperHttpConnection
Source§impl ErrorType for HyperHttpConnection
impl ErrorType for HyperHttpConnection
Source§type Error = HyperError
type Error = HyperError
The error type returned by this connection.
Source§impl Headers for HyperHttpConnection
impl Headers for HyperHttpConnection
Source§fn header(&self, name: &str) -> Option<&str>
fn header(&self, name: &str) -> Option<&str>
Retrieves a header value by name from the last response, if set.
fn content_type(&self) -> Option<&str>
fn content_len(&self) -> Option<u64>
fn content_encoding(&self) -> Option<&str>
fn transfer_encoding(&self) -> Option<&str>
fn host(&self) -> Option<&str>
fn connection(&self) -> Option<&str>
fn cache_control(&self) -> Option<&str>
fn upgrade(&self) -> Option<&str>
Source§impl Read for HyperHttpConnection
impl Read for HyperHttpConnection
Source§fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Self::Error>
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>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read moreSource§impl Status for HyperHttpConnection
impl Status for HyperHttpConnection
Source§impl Write for HyperHttpConnection
impl Write for HyperHttpConnection
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, HyperError>
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>
fn flush(&mut self) -> Result<(), HyperError>
Finalizes the request body by replacing it with the buffered data.