send user agent

This commit is contained in:
Robin Appelman 2024-12-26 00:53:17 +01:00
commit f8b59df362
6 changed files with 21 additions and 10 deletions

View file

@ -1,3 +1,4 @@
use crate::error::ConfigError;
use reqwest::header::{HeaderValue, InvalidHeaderValue};
use secretfile::{load, SecretError};
use serde::de::Error;
@ -8,7 +9,6 @@ use std::convert::{TryFrom, TryInto};
use std::fs::read_to_string;
use std::path::Path;
use tokio::time::Duration;
use crate::error::ConfigError;
#[derive(Debug, Deserialize)]
pub struct Config {
@ -29,10 +29,14 @@ pub struct FeedConfig {
impl Config {
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError> {
let path = path.as_ref();
let file = read_to_string(path)
.map_err(|error| ConfigError::Read {error, path: path.into()})?;
toml::from_str(&file)
.map_err(|error| ConfigError::Parse {error, path: path.into()})
let file = read_to_string(path).map_err(|error| ConfigError::Read {
error,
path: path.into(),
})?;
toml::from_str(&file).map_err(|error| ConfigError::Parse {
error,
path: path.into(),
})
}
pub fn interval(&self) -> Duration {

View file

@ -1,6 +1,6 @@
use reqwest::StatusCode;
use std::path::PathBuf;
use std::str::FromStr;
use reqwest::StatusCode;
use thiserror::Error;
#[derive(Debug, Error)]
@ -34,7 +34,7 @@ pub enum ConfigError {
},
#[error("Error while parse config file {}: {:#}", path.display(), error)]
Parse {
error: toml::de::Error,
error: toml::de::Error,
path: PathBuf,
},
}
@ -59,4 +59,4 @@ pub enum FetchError {
Feed(#[from] FetchFeedError),
#[error(transparent)]
Hub(#[from] HubError),
}
}

View file

@ -1,9 +1,11 @@
use crate::error::HubError;
use crate::fetcher::{CacheHeaders, FetchResponse};
use reqwest::Client;
use reqwest::header::{HeaderValue, USER_AGENT};
use serde::Deserialize;
use time::OffsetDateTime;
use tracing::instrument;
use crate::FETCHER_USER_AGENT;
#[instrument(skip(client))]
pub async fn tags(
@ -18,6 +20,7 @@ pub async fn tags(
user, repo
))
.headers(cache_headers.headers())
.header(USER_AGENT, HeaderValue::from_static(FETCHER_USER_AGENT))
.send()
.await;

View file

@ -14,12 +14,15 @@ use std::future::ready;
use std::hash::{Hash, Hasher};
use std::str::FromStr;
use std::time::{Duration};
use reqwest::header::{HeaderValue, USER_AGENT};
use syndication::Feed;
use tokio::select;
use tokio::signal::ctrl_c;
use tokio::time::sleep;
use tracing::{debug, error, info, instrument, warn};
const FETCHER_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"), "(", env!("CARGO_PKG_REPOSITORY"), ")");
#[tokio::main]
async fn main() -> MainResult {
tracing_subscriber::fmt::init();
@ -192,6 +195,7 @@ impl FeedFetcher {
.client
.get(feed)
.headers(cache_headers.headers())
.header(USER_AGENT, HeaderValue::from_static(FETCHER_USER_AGENT))
.send()
.await;