pooled_fetch/
lib.rs

1use std::net::SocketAddr;
2
3use http_body_util::Full;
4use hyper::{
5  Request, Response,
6  body::{Bytes, Incoming},
7  client::conn::http1::SendRequest,
8};
9
10mod body;
11mod error;
12mod http;
13pub use body::{Body, POOL};
14pub use error::{Error, Result};
15pub use http::http;
16
17pub type FullBytes = Full<Bytes>;
18pub type Send = SendRequest<FullBytes>;
19
20pub struct Sender {
21  pub send: Send,
22  pub conn: tokio::task::JoinHandle<()>,
23}
24
25pub struct Conn {
26  peer_addr: SocketAddr,
27  sender: Sender,
28}
29
30impl Conn {
31  pub async fn send(&mut self, req: Request<FullBytes>) -> hyper::Result<Response<Incoming>> {
32    self.sender.send.send_request(req).await
33  }
34  pub fn abort(&self) {
35    self.sender.conn.abort();
36  }
37}