1
0
Fork 0
mirror of https://github.com/dani-garcia/vaultwarden.git synced 2025-09-22 09:32:41 +00:00

Extract client creation to a single place

This commit is contained in:
Jake Howard 2021-04-06 21:04:37 +01:00
commit 155109dea1
No known key found for this signature in database
GPG key ID: 57AFB45680EDD477
5 changed files with 33 additions and 23 deletions

View file

@ -43,6 +43,7 @@ use crate::{
auth::Headers,
db::DbConn,
error::Error,
util::get_reqwest_client,
};
#[put("/devices/identifier/<uuid>/clear-token")]
@ -147,20 +148,16 @@ fn put_eq_domains(data: JsonUpcase<EquivDomainData>, headers: Headers, conn: DbC
#[get("/hibp/breach?<username>")]
fn hibp_breach(username: String) -> JsonResult {
let user_agent = "Bitwarden_RS";
let url = format!(
"https://haveibeenpwned.com/api/v3/breachedaccount/{}?truncateResponse=false&includeUnverified=false",
username
);
use reqwest::{blocking::Client, header::USER_AGENT};
if let Some(api_key) = crate::CONFIG.hibp_api_key() {
let hibp_client = Client::builder().build()?;
let hibp_client = get_reqwest_client();
let res = hibp_client
.get(&url)
.header(USER_AGENT, user_agent)
.header("hibp-api-key", api_key)
.send()?;