Skip to main content

HttpConnection

Struct HttpConnection 

Source
pub struct HttpConnection<S> { /* private fields */ }
Expand description

Async HTTP/1.1 keep-alive connection — pure transport.

Sends request bytes and reads response bytes over an async stream. All protocol logic lives in RequestWriter and ResponseReader.

§Usage

use nexus_net::rest::RequestWriter;
use nexus_net::http::ResponseReader;
use nexus_async_net::rest::{HttpConnection, HttpConnectionBuilder};
use nexus_net::tls::TlsConfig;

let mut writer = RequestWriter::new("api.binance.com").unwrap();
let mut reader = ResponseReader::new(32 * 1024);
let tls = TlsConfig::new()?;
let mut conn = HttpConnectionBuilder::new()
    .tls(&tls)
    .connect("https://api.binance.com")
    .await?;

let req = writer.get("/orders").query("symbol", "BTC").finish()?;
let resp = conn.send(req, &mut reader).await?;

Implementations§

Source§

impl<S: WireStream + Unpin> HttpConnection<S>

Source

pub fn new(stream: S) -> Self

Wrap a pre-connected async stream.

Source

pub fn builder() -> HttpConnectionBuilder

Create a builder.

Source

pub async fn send<'r>( &mut self, req: Request<'_>, reader: &'r mut ResponseReader, ) -> Result<RestResponse<'r>, RestError>

Send a request and read the response.

Same API as Client::send but with .await on I/O.

Source

pub fn is_poisoned(&self) -> bool

Whether the connection is poisoned.

Source

pub fn stream(&self) -> &S

Access the underlying stream.

Source

pub fn stream_mut(&mut self) -> &mut S

Mutable access to the underlying stream.

Auto Trait Implementations§

§

impl<S> Freeze for HttpConnection<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for HttpConnection<S>
where S: RefUnwindSafe,

§

impl<S> Send for HttpConnection<S>
where S: Send,

§

impl<S> Sync for HttpConnection<S>
where S: Sync,

§

impl<S> Unpin for HttpConnection<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for HttpConnection<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for HttpConnection<S>
where S: UnwindSafe,

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

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V