forked from Proxmox/proxmox
http: move SimpleHttpOptions to http-helpers feature
and rename it to HttpOptions, since it's not specific to the "Simple" client at all. this is a breaking change. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
e8d02db689
commit
ab5d5b39f6
@ -13,6 +13,5 @@ pub use connector::HttpsConnector;
|
||||
|
||||
mod simple;
|
||||
pub use simple::SimpleHttp;
|
||||
pub use simple::SimpleHttpOptions;
|
||||
|
||||
pub mod tls;
|
||||
|
@ -1,57 +1,39 @@
|
||||
use anyhow::{bail, format_err, Error};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
|
||||
use std::str::FromStr;
|
||||
|
||||
use futures::*;
|
||||
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
|
||||
use http::header::HeaderName;
|
||||
use http::{HeaderValue, Request, Response};
|
||||
use hyper::client::{Client, HttpConnector};
|
||||
use hyper::Body;
|
||||
use openssl::ssl::{SslConnector, SslMethod};
|
||||
|
||||
use crate::client::HttpsConnector;
|
||||
use crate::proxy_config::ProxyConfig;
|
||||
|
||||
/// Options for a SimpleHttp client.
|
||||
#[derive(Default)]
|
||||
pub struct SimpleHttpOptions {
|
||||
/// Proxy configuration
|
||||
pub proxy_config: Option<ProxyConfig>,
|
||||
/// `User-Agent` header value, defaults to `proxmox-simple-http-client/0.1`
|
||||
pub user_agent: Option<String>,
|
||||
/// TCP keepalive time, defaults to 7200
|
||||
pub tcp_keepalive: Option<u32>,
|
||||
}
|
||||
|
||||
impl SimpleHttpOptions {
|
||||
fn get_proxy_authorization(&self) -> Option<String> {
|
||||
if let Some(ref proxy_config) = self.proxy_config {
|
||||
if !proxy_config.force_connect {
|
||||
return proxy_config.authorization.clone();
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
use crate::HttpOptions;
|
||||
|
||||
/// Asyncrounous HTTP client implementation
|
||||
pub struct SimpleHttp {
|
||||
client: Client<HttpsConnector, Body>,
|
||||
options: SimpleHttpOptions,
|
||||
options: HttpOptions,
|
||||
}
|
||||
|
||||
impl SimpleHttp {
|
||||
pub const DEFAULT_USER_AGENT_STRING: &'static str = "proxmox-simple-http-client/0.1";
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self::with_options(SimpleHttpOptions::default())
|
||||
Self::with_options(HttpOptions::default())
|
||||
}
|
||||
|
||||
pub fn with_options(options: SimpleHttpOptions) -> Self {
|
||||
pub fn with_options(options: HttpOptions) -> Self {
|
||||
let ssl_connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
|
||||
Self::with_ssl_connector(ssl_connector, options)
|
||||
}
|
||||
|
||||
pub fn with_ssl_connector(ssl_connector: SslConnector, options: SimpleHttpOptions) -> Self {
|
||||
pub fn with_ssl_connector(ssl_connector: SslConnector, options: HttpOptions) -> Self {
|
||||
let connector = HttpConnector::new();
|
||||
let mut https = HttpsConnector::with_connector(
|
||||
connector,
|
||||
|
24
proxmox-http/src/http_options.rs
Normal file
24
proxmox-http/src/http_options.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use crate::ProxyConfig;
|
||||
|
||||
/// Options for an HTTP client.
|
||||
#[derive(Default)]
|
||||
pub struct HttpOptions {
|
||||
/// Proxy configuration
|
||||
pub proxy_config: Option<ProxyConfig>,
|
||||
/// `User-Agent` header value
|
||||
pub user_agent: Option<String>,
|
||||
/// TCP keepalive time, defaults to 7200
|
||||
pub tcp_keepalive: Option<u32>,
|
||||
}
|
||||
|
||||
impl HttpOptions {
|
||||
pub fn get_proxy_authorization(&self) -> Option<String> {
|
||||
if let Some(ref proxy_config) = self.proxy_config {
|
||||
if !proxy_config.force_connect {
|
||||
return proxy_config.authorization.clone();
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
@ -11,6 +11,11 @@ pub mod proxy_config;
|
||||
#[cfg(feature = "http-helpers")]
|
||||
pub use proxy_config::ProxyConfig;
|
||||
|
||||
#[cfg(feature = "http-helpers")]
|
||||
mod http_options;
|
||||
#[cfg(feature = "http-helpers")]
|
||||
pub use http_options::HttpOptions;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
pub mod client;
|
||||
|
||||
|
@ -3,9 +3,10 @@ use std::sync::Arc;
|
||||
use anyhow::{bail, Error};
|
||||
use hyper::Body;
|
||||
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
||||
use proxmox_http::HttpOptions;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use proxmox_http::client::{SimpleHttp, SimpleHttpOptions};
|
||||
use proxmox_http::client::SimpleHttp;
|
||||
|
||||
use crate::influxdb::utils;
|
||||
use crate::{Metrics, MetricsData};
|
||||
@ -76,11 +77,11 @@ impl InfluxDbHttp {
|
||||
channel: mpsc::Receiver<Arc<MetricsData>>,
|
||||
) -> Result<Self, Error> {
|
||||
let client = if verify_tls {
|
||||
SimpleHttp::with_options(SimpleHttpOptions::default())
|
||||
SimpleHttp::with_options(HttpOptions::default())
|
||||
} else {
|
||||
let mut ssl_connector = SslConnector::builder(SslMethod::tls()).unwrap();
|
||||
ssl_connector.set_verify(SslVerifyMode::NONE);
|
||||
SimpleHttp::with_ssl_connector(ssl_connector.build(), SimpleHttpOptions::default())
|
||||
SimpleHttp::with_ssl_connector(ssl_connector.build(), HttpOptions::default())
|
||||
};
|
||||
|
||||
let uri: http::uri::Uri = uri.parse()?;
|
||||
|
Loading…
Reference in New Issue
Block a user