mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-07 19:03:20 +00:00
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;
|
mod simple;
|
||||||
pub use simple::SimpleHttp;
|
pub use simple::SimpleHttp;
|
||||||
pub use simple::SimpleHttpOptions;
|
|
||||||
|
|
||||||
pub mod tls;
|
pub mod tls;
|
||||||
|
@ -1,57 +1,39 @@
|
|||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use futures::*;
|
use futures::*;
|
||||||
|
#[cfg(all(feature = "client-trait", feature = "proxmox-async"))]
|
||||||
|
use http::header::HeaderName;
|
||||||
use http::{HeaderValue, Request, Response};
|
use http::{HeaderValue, Request, Response};
|
||||||
use hyper::client::{Client, HttpConnector};
|
use hyper::client::{Client, HttpConnector};
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
use openssl::ssl::{SslConnector, SslMethod};
|
use openssl::ssl::{SslConnector, SslMethod};
|
||||||
|
|
||||||
use crate::client::HttpsConnector;
|
use crate::client::HttpsConnector;
|
||||||
use crate::proxy_config::ProxyConfig;
|
use crate::HttpOptions;
|
||||||
|
|
||||||
/// 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Asyncrounous HTTP client implementation
|
/// Asyncrounous HTTP client implementation
|
||||||
pub struct SimpleHttp {
|
pub struct SimpleHttp {
|
||||||
client: Client<HttpsConnector, Body>,
|
client: Client<HttpsConnector, Body>,
|
||||||
options: SimpleHttpOptions,
|
options: HttpOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SimpleHttp {
|
impl SimpleHttp {
|
||||||
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 {
|
||||||
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();
|
let ssl_connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
|
||||||
Self::with_ssl_connector(ssl_connector, options)
|
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 connector = HttpConnector::new();
|
||||||
let mut https = HttpsConnector::with_connector(
|
let mut https = HttpsConnector::with_connector(
|
||||||
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")]
|
#[cfg(feature = "http-helpers")]
|
||||||
pub use proxy_config::ProxyConfig;
|
pub use proxy_config::ProxyConfig;
|
||||||
|
|
||||||
|
#[cfg(feature = "http-helpers")]
|
||||||
|
mod http_options;
|
||||||
|
#[cfg(feature = "http-helpers")]
|
||||||
|
pub use http_options::HttpOptions;
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
|
||||||
|
@ -3,9 +3,10 @@ use std::sync::Arc;
|
|||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
||||||
|
use proxmox_http::HttpOptions;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use proxmox_http::client::{SimpleHttp, SimpleHttpOptions};
|
use proxmox_http::client::SimpleHttp;
|
||||||
|
|
||||||
use crate::influxdb::utils;
|
use crate::influxdb::utils;
|
||||||
use crate::{Metrics, MetricsData};
|
use crate::{Metrics, MetricsData};
|
||||||
@ -76,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(SimpleHttpOptions::default())
|
SimpleHttp::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(), SimpleHttpOptions::default())
|
SimpleHttp::with_ssl_connector(ssl_connector.build(), HttpOptions::default())
|
||||||
};
|
};
|
||||||
|
|
||||||
let uri: http::uri::Uri = uri.parse()?;
|
let uri: http::uri::Uri = uri.parse()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user