From 3c27383bbce2c464efad5bca338dbdf464b0729a Mon Sep 17 00:00:00 2001 From: Matteo Settenvini Date: Sat, 2 Jul 2022 20:55:03 +0200 Subject: [PATCH] Add user agent to HTTP requests --- src/config/credentials.rs | 5 ++++- src/constants.rs | 4 ++++ src/main.rs | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/constants.rs diff --git a/src/config/credentials.rs b/src/config/credentials.rs index 53c15a3..31d79e3 100644 --- a/src/config/credentials.rs +++ b/src/config/credentials.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use { + crate::constants::USER_AGENT, anyhow::{anyhow, Result}, reqwest::{StatusCode, Url}, serde::{Deserialize, Serialize}, @@ -46,7 +47,9 @@ impl Credentials { } pub fn add(&mut self, server: Url) -> Result<()> { - let http_client = reqwest::blocking::Client::new(); + let http_client = reqwest::blocking::Client::builder() + .user_agent(USER_AGENT) + .build()?; #[derive(Deserialize)] struct LoginFlow { diff --git a/src/constants.rs b/src/constants.rs new file mode 100644 index 0000000..8fb4a1c --- /dev/null +++ b/src/constants.rs @@ -0,0 +1,4 @@ +// SPDX-FileCopyrightText: 2022 Matteo Settenvini +// SPDX-License-Identifier: AGPL-3.0-or-later + +pub const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); diff --git a/src/main.rs b/src/main.rs index 93b842e..5aee557 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later mod config; +mod constants; use { self::config::Config,