From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 5/8] move ProxyConfig to proxmox_http
Date: Fri, 14 May 2021 15:44:54 +0200 [thread overview]
Message-ID: <20210514134457.1447930-19-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20210514134457.1447930-1-f.gruenbichler@proxmox.com>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
Notes:
requires proxmox patch #7 & #8
src/api2/node/apt.rs | 4 +-
src/api2/types/mod.rs | 2 +-
src/config/node.rs | 3 +-
src/tools/http.rs | 82 +--------------------------------
src/tools/simple_http_client.rs | 4 +-
5 files changed, 10 insertions(+), 85 deletions(-)
diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
index c149a14b..120d5339 100644
--- a/src/api2/node/apt.rs
+++ b/src/api2/node/apt.rs
@@ -7,9 +7,11 @@ use proxmox::api::{api, RpcEnvironment, RpcEnvironmentType, Permission};
use proxmox::api::router::{Router, SubdirMap};
use proxmox::tools::fs::{replace_file, CreateOptions};
+use proxmox_http::http::ProxyConfig;
+
use crate::config::node;
use crate::server::WorkerTask;
-use crate::tools::{apt, SimpleHttp, http::ProxyConfig, subscription};
+use crate::tools::{apt, SimpleHttp, subscription};
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
use crate::api2::types::{Authid, APTUpdateInfo, NODE_SCHEMA, UPID_SCHEMA};
diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs
index e42083f0..26b99790 100644
--- a/src/api2/types/mod.rs
+++ b/src/api2/types/mod.rs
@@ -1660,7 +1660,7 @@ pub struct NodeStatus {
pub const HTTP_PROXY_SCHEMA: Schema = StringSchema::new(
"HTTP proxy configuration [http://]<host>[:port]")
.format(&ApiStringFormat::VerifyFn(|s| {
- crate::tools::http::ProxyConfig::parse_proxy_url(s)?;
+ proxmox_http::http::ProxyConfig::parse_proxy_url(s)?;
Ok(())
}))
.min_length(1)
diff --git a/src/config/node.rs b/src/config/node.rs
index e818e47e..b003ae01 100644
--- a/src/config/node.rs
+++ b/src/config/node.rs
@@ -10,11 +10,12 @@ use proxmox::api::api;
use proxmox::api::schema::{ApiStringFormat, Updater};
use proxmox::tools::fs::{replace_file, CreateOptions};
+use proxmox_http::http::ProxyConfig;
+
use crate::acme::AcmeClient;
use crate::api2::types::{
AcmeAccountName, AcmeDomain, ACME_DOMAIN_PROPERTY_SCHEMA, HTTP_PROXY_SCHEMA,
};
-use crate::tools::http::ProxyConfig;
const CONF_FILE: &str = configdir!("/node.cfg");
const LOCK_FILE: &str = configdir!("/.node.lck");
diff --git a/src/tools/http.rs b/src/tools/http.rs
index a6b92aad..b99d26a1 100644
--- a/src/tools/http.rs
+++ b/src/tools/http.rs
@@ -19,7 +19,7 @@ use tokio::{
use tokio_openssl::SslStream;
use proxmox::sys::linux::socket::set_tcp_keepalive;
-use proxmox_http::http::MaybeTlsStream;
+use proxmox_http::http::{MaybeTlsStream, ProxyConfig};
// Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses
pub(crate) fn build_authority(host: &str, port: u16) -> Result<Authority, Error> {
@@ -33,86 +33,6 @@ pub(crate) fn build_authority(host: &str, port: u16) -> Result<Authority, Error>
Ok(authority)
}
-/// HTTP Proxy Configuration
-#[derive(Clone)]
-pub struct ProxyConfig {
- pub host: String,
- pub port: u16,
- pub authorization: Option<String>, // user:pass
- pub force_connect: bool,
-}
-
-impl ProxyConfig {
-
- /// Parse proxy config from ALL_PROXY environment var
- pub fn from_proxy_env() -> Result<Option<ProxyConfig>, Error> {
-
- // We only support/use ALL_PROXY environment
-
- match std::env::var_os("ALL_PROXY") {
- None => return Ok(None),
- Some(all_proxy) => {
- let all_proxy = match all_proxy.to_str() {
- Some(s) => String::from(s),
- None => bail!("non UTF-8 content in env ALL_PROXY"),
- };
- if all_proxy.is_empty() {
- return Ok(None);
- }
- let config = Self::parse_proxy_url(&all_proxy)?;
- Ok(Some(config))
- }
- }
- }
-
- /// Parse proxy configuration string [http://]<host>[:port]
- ///
- /// Default port is 1080 (like curl)
- pub fn parse_proxy_url(http_proxy: &str) -> Result<ProxyConfig, Error> {
- proxmox::try_block!({
- let proxy_uri: Uri = http_proxy.parse()?;
- let proxy_authority = match proxy_uri.authority() {
- Some(authority) => authority,
- None => bail!("missing proxy authority"),
- };
- let host = proxy_authority.host().to_owned();
- let port = match proxy_uri.port() {
- Some(port) => port.as_u16(),
- None => 1080, // CURL default port
- };
-
- match proxy_uri.scheme_str() {
- Some("http") => { /* Ok */ }
- Some(scheme) => bail!("unsupported proxy scheme '{}'", scheme),
- None => { /* assume HTTP */ }
- }
-
- let authority_vec: Vec<&str> = proxy_authority.as_str().rsplitn(2, '@').collect();
- let authorization = if authority_vec.len() == 2 {
- Some(authority_vec[1].to_string())
- } else {
- None
- };
-
- Ok(ProxyConfig {
- host,
- port,
- authorization,
- force_connect: false,
- })
- }).map_err(|err| format_err!("parse_proxy_url failed: {}", err))
- }
-
- /// Assemble canonical proxy string (including scheme and port)
- pub fn to_proxy_string(&self) -> Result<String, Error> {
- let authority = build_authority(&self.host, self.port)?;
- Ok(match self.authorization {
- None => format!("http://{}", authority),
- Some(ref authorization) => format!("http://{}@{}", authorization, authority)
- })
- }
-}
-
#[derive(Clone)]
pub struct HttpsConnector {
connector: HttpConnector,
diff --git a/src/tools/simple_http_client.rs b/src/tools/simple_http_client.rs
index 1e399267..729711c8 100644
--- a/src/tools/simple_http_client.rs
+++ b/src/tools/simple_http_client.rs
@@ -7,8 +7,10 @@ use http::{Request, Response, HeaderValue};
use openssl::ssl::{SslConnector, SslMethod};
use futures::*;
+use proxmox_http::http::ProxyConfig;
+
use crate::tools::PROXMOX_BACKUP_TCP_KEEPALIVE_TIME;
-use crate::tools::http::{HttpsConnector, ProxyConfig};
+use crate::tools::http::HttpsConnector;
/// Asyncrounous HTTP client implementation
pub struct SimpleHttp {
--
2.20.1
next prev parent reply other threads:[~2021-05-14 13:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-14 13:44 [pbs-devel] [PATCH proxmox(-backup) 00/21] pull HTTP code into proxmox/proxmox-http Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 01/13] proxmox: add missing +router -> futures dep Fabian Grünbichler
2021-05-17 8:22 ` [pbs-devel] applied: " Dietmar Maurer
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 02/13] meta: add empty proxmox-http sub-crate Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 03/13] http: takeover websocket feature from proxmox Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 04/13] http: make clippy happy Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 05/13] proxmox: takeover socket helper from proxmox_backup Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 06/13] http: takeover MaybeTlsStream " Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 07/13] http: takeover build_authority helper " Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 08/13] http: takeover ProxyConfig " Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 09/13] http: takeover tools::http " Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 10/13] http: takeover simple HTTP client " Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 11/13] http: make clippy happy Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 12/13] http: rustfmt Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox 13/13] http: update d/control Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox-backup 1/8] move websocket to new 'proxmox_http' crate Fabian Grünbichler
2021-05-17 8:35 ` [pbs-devel] applied: " Dietmar Maurer
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox-backup 2/8] refactor: move socket helper to proxmox crate Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox-backup 3/8] move MaybeTlsStream wrapper to proxmox_http Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox-backup 4/8] HttpsConnector: make keepalive configurable Fabian Grünbichler
2021-05-14 13:44 ` Fabian Grünbichler [this message]
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox-backup 6/8] move tools::http to proxmox_http Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox-backup 7/8] SimpleHttp: factor out product-specific bits Fabian Grünbichler
2021-05-14 13:44 ` [pbs-devel] [PATCH proxmox-backup 8/8] move SimpleHttp to proxmox_http Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210514134457.1447930-19-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox