http: rename SimpleHttp to Client

so we have proxmox_http::client::Client for the async, hyper-based
client and proxmox_http::client::sync::Client for the sync, ureq-based
one.

this is a breaking change.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2022-08-04 10:03:36 +02:00
parent 7ffb895062
commit da49b98d15
4 changed files with 16 additions and 15 deletions

View File

@ -1,7 +1,7 @@
//! Simple TLS capable HTTP client implementations. //! Simple TLS capable HTTP client implementations.
//! //!
//! Feature `client` contains a lightweight wrapper around `hyper` with support for TLS connections //! Feature `client` contains a lightweight wrapper around `hyper` with support for TLS connections
//! in [`SimpleHttp`](crate::client::SimpleHttp). //! in [`Client`](crate::client::Client).
//! //!
//! Feature `client-sync` contains a lightweight wrapper around `ureq` in //! Feature `client-sync` contains a lightweight wrapper around `ureq` in
//! [`sync::Client`](crate::client::sync::Client). //! [`sync::Client`](crate::client::sync::Client).
@ -26,7 +26,7 @@ pub use connector::HttpsConnector;
#[cfg(feature = "client")] #[cfg(feature = "client")]
mod simple; mod simple;
#[cfg(feature = "client")] #[cfg(feature = "client")]
pub use simple::SimpleHttp; pub use simple::Client;
#[cfg(feature = "client")] #[cfg(feature = "client")]
pub mod tls; pub mod tls;

View File

@ -8,7 +8,8 @@ use futures::*;
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))] #[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
use http::header::HeaderName; use http::header::HeaderName;
use http::{HeaderValue, Request, Response}; use http::{HeaderValue, Request, Response};
use hyper::client::{Client, HttpConnector}; use hyper::client::Client as HyperClient;
use hyper::client::HttpConnector;
use hyper::Body; use hyper::Body;
use openssl::ssl::{SslConnector, SslMethod}; use openssl::ssl::{SslConnector, SslMethod};
@ -16,12 +17,12 @@ use crate::client::HttpsConnector;
use crate::HttpOptions; use crate::HttpOptions;
/// Asyncrounous HTTP client implementation /// Asyncrounous HTTP client implementation
pub struct SimpleHttp { pub struct Client {
client: Client<HttpsConnector, Body>, client: HyperClient<HttpsConnector, Body>,
options: HttpOptions, options: HttpOptions,
} }
impl SimpleHttp { impl Client {
pub const DEFAULT_USER_AGENT_STRING: &'static str = "proxmox-simple-http-client/0.1"; pub const DEFAULT_USER_AGENT_STRING: &'static str = "proxmox-simple-http-client/0.1";
pub fn new() -> Self { pub fn new() -> Self {
@ -43,7 +44,7 @@ impl SimpleHttp {
if let Some(ref proxy_config) = options.proxy_config { if let Some(ref proxy_config) = options.proxy_config {
https.set_proxy(proxy_config.clone()); https.set_proxy(proxy_config.clone());
} }
let client = Client::builder().build(https); let client = HyperClient::builder().build(https);
Self { client, options } Self { client, options }
} }
@ -151,14 +152,14 @@ impl SimpleHttp {
} }
} }
impl Default for SimpleHttp { impl Default for Client {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }
} }
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))] #[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
impl crate::HttpClient<Body> for SimpleHttp { impl crate::HttpClient<Body> for Client {
fn get( fn get(
&self, &self,
uri: &str, uri: &str,
@ -194,7 +195,7 @@ impl crate::HttpClient<Body> for SimpleHttp {
} }
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))] #[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
impl crate::HttpClient<String> for SimpleHttp { impl crate::HttpClient<String> for Client {
fn get( fn get(
&self, &self,
uri: &str, uri: &str,

View File

@ -1,6 +1,6 @@
//! HTTP proxy configuration. //! HTTP proxy configuration.
//! //!
//! This can be used with the async [`SimpleHttp`](crate::client::SimpleHttp) or sync [`Client`](crate::client::sync::Client). //! This can be used with the async [`Client`](crate::client::Client) or sync [`Client`](crate::client::sync::Client).
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};

View File

@ -6,13 +6,13 @@ use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
use proxmox_http::HttpOptions; use proxmox_http::HttpOptions;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use proxmox_http::client::SimpleHttp; use proxmox_http::client::Client;
use crate::influxdb::utils; use crate::influxdb::utils;
use crate::{Metrics, MetricsData}; use crate::{Metrics, MetricsData};
struct InfluxDbHttp { struct InfluxDbHttp {
client: SimpleHttp, client: Client,
healthuri: http::Uri, healthuri: http::Uri,
writeuri: http::Uri, writeuri: http::Uri,
token: Option<String>, token: Option<String>,
@ -77,11 +77,11 @@ impl InfluxDbHttp {
channel: mpsc::Receiver<Arc<MetricsData>>, channel: mpsc::Receiver<Arc<MetricsData>>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let client = if verify_tls { let client = if verify_tls {
SimpleHttp::with_options(HttpOptions::default()) Client::with_options(HttpOptions::default())
} else { } else {
let mut ssl_connector = SslConnector::builder(SslMethod::tls()).unwrap(); let mut ssl_connector = SslConnector::builder(SslMethod::tls()).unwrap();
ssl_connector.set_verify(SslVerifyMode::NONE); ssl_connector.set_verify(SslVerifyMode::NONE);
SimpleHttp::with_ssl_connector(ssl_connector.build(), HttpOptions::default()) Client::with_ssl_connector(ssl_connector.build(), HttpOptions::default())
}; };
let uri: http::uri::Uri = uri.parse()?; let uri: http::uri::Uri = uri.parse()?;