From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 1/2] tools/http: set USER_AGENT inside request
Date: Wed, 28 Apr 2021 12:03:57 +0200 [thread overview]
Message-ID: <20210428100358.25850-1-dietmar@proxmox.com> (raw)
---
src/tools/http.rs | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/tools/http.rs b/src/tools/http.rs
index f4ccefc9..a4299fb4 100644
--- a/src/tools/http.rs
+++ b/src/tools/http.rs
@@ -107,6 +107,8 @@ pub struct SimpleHttp {
impl SimpleHttp {
+ pub const DEFAULT_USER_AGENT_STRING: &'static str = "proxmox-backup-client/1.0";
+
pub fn new(proxy_config: Option<ProxyConfig>) -> Self {
let ssl_connector = SslConnector::builder(SslMethod::tls()).unwrap().build();
Self::with_ssl_connector(ssl_connector, proxy_config)
@@ -145,7 +147,14 @@ impl SimpleHttp {
}
pub async fn request(&self, mut request: Request<Body>) -> Result<Response<Body>, Error> {
+
+ request.headers_mut().insert(
+ hyper::header::USER_AGENT,
+ HeaderValue::from_str(Self::DEFAULT_USER_AGENT_STRING)?,
+ );
+
self.add_proxy_headers(&mut request)?;
+
self.client.request(request)
.map_err(Error::from)
.await
@@ -168,7 +177,6 @@ impl SimpleHttp {
let request = Request::builder()
.method("POST")
.uri(uri)
- .header("User-Agent", "proxmox-backup-client/1.0")
.header(hyper::header::CONTENT_TYPE, content_type)
.body(body)?;
@@ -183,8 +191,7 @@ impl SimpleHttp {
let mut request = Request::builder()
.method("GET")
- .uri(uri)
- .header("User-Agent", "proxmox-backup-client/1.0");
+ .uri(uri);
if let Some(hs) = extra_headers {
for (h, v) in hs.iter() {
--
2.20.1
next reply other threads:[~2021-04-28 10:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 10:03 Dietmar Maurer [this message]
2021-04-28 10:03 ` [pbs-devel] [PATCH proxmox-backup 2/2] tools/http: make user agent configurable Dietmar Maurer
2021-04-28 14:23 ` Wolfgang Bumiller
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=20210428100358.25850-1-dietmar@proxmox.com \
--to=dietmar@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