From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Dietmar Maurer <dietmar@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox-backup 2/2] tools/http: make user agent configurable
Date: Wed, 28 Apr 2021 16:23:39 +0200 [thread overview]
Message-ID: <20210428142339.rvaisxu3shiwrckk@wobu-vie.proxmox.com> (raw)
In-Reply-To: <20210428100358.25850-2-dietmar@proxmox.com>
Do we really need to have more than 1 user agent string in what's
basically a non-exported utility, though?
On Wed, Apr 28, 2021 at 12:03:58PM +0200, Dietmar Maurer wrote:
> ---
> src/tools/http.rs | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/src/tools/http.rs b/src/tools/http.rs
> index a4299fb4..8656e685 100644
> --- a/src/tools/http.rs
> +++ b/src/tools/http.rs
> @@ -103,6 +103,7 @@ impl ProxyConfig {
> pub struct SimpleHttp {
> client: Client<HttpsConnector, Body>,
> proxy_authorization: Option<String>, // Proxy-Authorization header value
> + user_agent: Option<String>,
> }
>
> impl SimpleHttp {
> @@ -129,7 +130,12 @@ impl SimpleHttp {
> https.set_proxy(proxy_config);
> }
> let client = Client::builder().build(https);
> - Self { client, proxy_authorization}
> + Self { client, proxy_authorization, user_agent: None }
> + }
> +
> + pub fn set_user_agent(&mut self, user_agent: &str) -> Result<(), Error> {
> + self.user_agent = Some(user_agent.to_owned());
> + Ok(())
> }
>
> fn add_proxy_headers(&self, request: &mut Request<Body>) -> Result<(), Error> {
> @@ -147,11 +153,13 @@ impl SimpleHttp {
> }
>
> pub async fn request(&self, mut request: Request<Body>) -> Result<Response<Body>, Error> {
> + let user_agent = if let Some(ref user_agent) = self.user_agent {
> + HeaderValue::from_str(&user_agent)?
> + } else {
> + HeaderValue::from_str(Self::DEFAULT_USER_AGENT_STRING)?
> + };
>
> - request.headers_mut().insert(
> - hyper::header::USER_AGENT,
> - HeaderValue::from_str(Self::DEFAULT_USER_AGENT_STRING)?,
> - );
> + request.headers_mut().insert(hyper::header::USER_AGENT, user_agent);
>
> self.add_proxy_headers(&mut request)?;
>
> --
> 2.20.1
next prev parent reply other threads:[~2021-04-28 14:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 10:03 [pbs-devel] [PATCH proxmox-backup 1/2] tools/http: set USER_AGENT inside request Dietmar Maurer
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 [this message]
2021-04-28 15:31 Dietmar Maurer
2021-04-28 15:44 Dietmar Maurer
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=20210428142339.rvaisxu3shiwrckk@wobu-vie.proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=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