mirror of
https://github.com/openai/codex.git
synced 2026-10-28 18:58:46 +00:00
core-plugins: route requests through HTTP client factory
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use http::Error as HttpError;
|
||||
use http::Error as HttpRequestBuildError;
|
||||
use http::HeaderMap;
|
||||
use http::HeaderName;
|
||||
use http::HeaderValue;
|
||||
@@ -6,13 +6,15 @@ use opentelemetry::global;
|
||||
use opentelemetry::propagation::Injector;
|
||||
use reqwest::IntoUrl;
|
||||
use reqwest::Method;
|
||||
use reqwest::Response;
|
||||
use serde::Serialize;
|
||||
use std::fmt::Display;
|
||||
use std::time::Duration;
|
||||
use tracing::Span;
|
||||
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
||||
|
||||
pub type HttpError = reqwest::Error;
|
||||
pub type HttpResponse = reqwest::Response;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct HttpClient {
|
||||
inner: reqwest::Client,
|
||||
@@ -37,6 +39,20 @@ impl HttpClient {
|
||||
self.request(Method::POST, url)
|
||||
}
|
||||
|
||||
pub fn put<U>(&self, url: U) -> RequestBuilder
|
||||
where
|
||||
U: IntoUrl,
|
||||
{
|
||||
self.request(Method::PUT, url)
|
||||
}
|
||||
|
||||
pub fn delete<U>(&self, url: U) -> RequestBuilder
|
||||
where
|
||||
U: IntoUrl,
|
||||
{
|
||||
self.request(Method::DELETE, url)
|
||||
}
|
||||
|
||||
pub fn request<U>(&self, method: Method, url: U) -> RequestBuilder
|
||||
where
|
||||
U: IntoUrl,
|
||||
@@ -78,9 +94,9 @@ impl RequestBuilder {
|
||||
pub fn header<K, V>(self, key: K, value: V) -> Self
|
||||
where
|
||||
HeaderName: TryFrom<K>,
|
||||
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
|
||||
<HeaderName as TryFrom<K>>::Error: Into<HttpRequestBuildError>,
|
||||
HeaderValue: TryFrom<V>,
|
||||
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
|
||||
<HeaderValue as TryFrom<V>>::Error: Into<HttpRequestBuildError>,
|
||||
{
|
||||
self.map(|builder| builder.header(key, value))
|
||||
}
|
||||
@@ -110,7 +126,7 @@ impl RequestBuilder {
|
||||
self.map(|builder| builder.body(body))
|
||||
}
|
||||
|
||||
pub async fn send(self) -> Result<Response, reqwest::Error> {
|
||||
pub async fn send(self) -> Result<HttpResponse, HttpError> {
|
||||
let headers = trace_headers();
|
||||
|
||||
match self.builder.headers(headers).send().await {
|
||||
|
||||
@@ -22,6 +22,8 @@ pub use crate::custom_ca::build_reqwest_client_with_custom_ca;
|
||||
pub use crate::custom_ca::build_rustls_client_config_with_custom_ca;
|
||||
pub use crate::custom_ca::maybe_build_rustls_client_config_with_custom_ca;
|
||||
pub use crate::default_client::HttpClient;
|
||||
pub use crate::default_client::HttpError;
|
||||
pub use crate::default_client::HttpResponse;
|
||||
pub use crate::default_client::RequestBuilder;
|
||||
pub use crate::error::StreamError;
|
||||
pub use crate::error::TransportError;
|
||||
|
||||
Reference in New Issue
Block a user