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>
impl<S: WireStream + Unpin> HttpConnection<S>
Sourcepub fn builder() -> HttpConnectionBuilder
pub fn builder() -> HttpConnectionBuilder
Create a builder.
Sourcepub async fn send<'r>(
&mut self,
req: Request<'_>,
reader: &'r mut ResponseReader,
) -> Result<RestResponse<'r>, RestError>
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.
Sourcepub fn is_poisoned(&self) -> bool
pub fn is_poisoned(&self) -> bool
Whether the connection is poisoned.
Sourcepub fn stream_mut(&mut self) -> &mut S
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more