chore: add user agent to reqwests
parent
b2e6335028
commit
00bf65c596
|
@ -3,6 +3,7 @@ use std::sync::Arc;
|
|||
use super::Extractor;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::Result;
|
||||
use upend::common::APP_USER_AGENT;
|
||||
use upend::{
|
||||
addressing::Address,
|
||||
database::{entry::Entry, stores::UpStore, UpEndConnection},
|
||||
|
@ -26,7 +27,11 @@ impl Extractor for WebExtractor {
|
|||
job_container.add_job(None, &format!("Getting info about {url:?}"))?;
|
||||
|
||||
let webpage_url = url.clone();
|
||||
let webpage_get = Webpage::from_url(webpage_url.as_ref(), WebpageOptions::default());
|
||||
let options = WebpageOptions {
|
||||
useragent: APP_USER_AGENT.to_string(),
|
||||
..WebpageOptions::default()
|
||||
};
|
||||
let webpage_get = Webpage::from_url(webpage_url.as_ref(), options);
|
||||
|
||||
if let Ok(webpage) = webpage_get {
|
||||
let _ = job_handle.update_progress(50.0);
|
||||
|
|
|
@ -19,6 +19,7 @@ use tracing::trace;
|
|||
use tracing::{debug, error, info, warn};
|
||||
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
|
||||
use upend::addressing::Address;
|
||||
use upend::common::APP_USER_AGENT;
|
||||
use upend::database::entry::EntryValue;
|
||||
use upend::util::hash::hash;
|
||||
|
||||
|
@ -197,7 +198,9 @@ fn main() -> Result<()> {
|
|||
let api_url = url.join("/api/query")?;
|
||||
|
||||
debug!("Querying \"{}\"", api_url);
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.user_agent(APP_USER_AGENT.as_str())
|
||||
.build()?;
|
||||
let response = client.post(api_url).body(query).send()?;
|
||||
|
||||
response.error_for_status_ref()?;
|
||||
|
@ -205,9 +208,7 @@ fn main() -> Result<()> {
|
|||
match format {
|
||||
OutputFormat::Json | OutputFormat::Raw => println!("{}", response.text()?),
|
||||
OutputFormat::Tsv => {
|
||||
eprintln!(
|
||||
"entity\tattribute\tvalue\ttimestamp\tprovenance"
|
||||
);
|
||||
eprintln!("entity\tattribute\tvalue\ttimestamp\tprovenance");
|
||||
response
|
||||
.json::<HashMap<String, serde_json::Value>>()?
|
||||
.iter()
|
||||
|
@ -216,10 +217,7 @@ fn main() -> Result<()> {
|
|||
"{}\t{}\t{}\t{}\t{}",
|
||||
entry.get("entity").and_then(|e| e.as_str()).unwrap(),
|
||||
entry.get("attribute").and_then(|a| a.as_str()).unwrap(),
|
||||
entry
|
||||
.get("value")
|
||||
.and_then(|v| v.get("c"))
|
||||
.unwrap(),
|
||||
entry.get("value").and_then(|v| v.get("c")).unwrap(),
|
||||
entry.get("timestamp").and_then(|t| t.as_str()).unwrap(),
|
||||
entry.get("provenance").and_then(|p| p.as_str()).unwrap(),
|
||||
)
|
||||
|
@ -254,7 +252,9 @@ fn main() -> Result<()> {
|
|||
});
|
||||
|
||||
debug!("Inserting {:?} at \"{}\"", body, api_url);
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.user_agent(APP_USER_AGENT.as_str())
|
||||
.build()?;
|
||||
let response = client.put(api_url).json(&body).send()?;
|
||||
|
||||
match response.error_for_status_ref() {
|
||||
|
|
|
@ -17,3 +17,7 @@ pub fn get_static_dir<S: AsRef<str>>(dir: S) -> Result<std::path::PathBuf> {
|
|||
Err(anyhow!("Path {result:?} doesn't exist."))
|
||||
}
|
||||
}
|
||||
lazy_static! {
|
||||
pub static ref APP_USER_AGENT: String =
|
||||
format!("{} / {}", build::PROJECT_NAME, build::PKG_VERSION);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue