use std::sync::LazyLock;
use super::{HttpClient, HttpResponse};
use bytes::Bytes;
use http::{HeaderMap, Request, StatusCode};
impl HttpClient for reqwest::Client {
type Response = reqwest::Response;
type Error = reqwest::Error;
async fn execute(&self, request: Request<Bytes>) -> Result<Self::Response, Self::Error> {
let (parts, body) = request.into_parts();
let reqwest_request = self
.request(parts.method, parts.uri.to_string())
.headers(parts.headers)
.body(body)
.build()?;
reqwest::Client::execute(self, reqwest_request).await
}
}
impl HttpClient for LazyLock<reqwest::Client> {
type Response = reqwest::Response;
type Error = reqwest::Error;
async fn execute(&self, request: Request<Bytes>) -> Result<Self::Response, Self::Error> {
let (parts, body) = request.into_parts();
let reqwest_request = self
.request(parts.method, parts.uri.to_string())
.headers(parts.headers)
.body(body)
.build()?;
reqwest::Client::execute(self, reqwest_request).await
}
}
impl HttpResponse for reqwest::Response {
type Error = reqwest::Error;
fn status(&self) -> StatusCode {
self.status()
}
fn headers(&self) -> HeaderMap {
self.headers().clone()
}
async fn body(self) -> Result<Bytes, Self::Error> {
self.bytes().await
}
}
impl crate::Error for reqwest::Error {
fn is_retryable(&self) -> bool {
self.is_connect()
}
}