mirror of
https://codeberg.org/icewind/rss-webhook-trigger.git
synced 2026-06-03 09:54:18 +02:00
send user agent
This commit is contained in:
parent
988f2e4603
commit
f8b59df362
6 changed files with 21 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -997,7 +997,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rss-webhook-trigger"
|
name = "rss-webhook-trigger"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"main_error",
|
"main_error",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rss-webhook-trigger"
|
name = "rss-webhook-trigger"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
rust-version = "1.71.1"
|
rust-version = "1.71.1"
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::error::ConfigError;
|
||||||
use reqwest::header::{HeaderValue, InvalidHeaderValue};
|
use reqwest::header::{HeaderValue, InvalidHeaderValue};
|
||||||
use secretfile::{load, SecretError};
|
use secretfile::{load, SecretError};
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
|
|
@ -8,7 +9,6 @@ use std::convert::{TryFrom, TryInto};
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tokio::time::Duration;
|
use tokio::time::Duration;
|
||||||
use crate::error::ConfigError;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
@ -29,10 +29,14 @@ pub struct FeedConfig {
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError> {
|
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let file = read_to_string(path)
|
let file = read_to_string(path).map_err(|error| ConfigError::Read {
|
||||||
.map_err(|error| ConfigError::Read {error, path: path.into()})?;
|
error,
|
||||||
toml::from_str(&file)
|
path: path.into(),
|
||||||
.map_err(|error| ConfigError::Parse {error, path: path.into()})
|
})?;
|
||||||
|
toml::from_str(&file).map_err(|error| ConfigError::Parse {
|
||||||
|
error,
|
||||||
|
path: path.into(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn interval(&self) -> Duration {
|
pub fn interval(&self) -> Duration {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
use reqwest::StatusCode;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use reqwest::StatusCode;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
@ -34,7 +34,7 @@ pub enum ConfigError {
|
||||||
},
|
},
|
||||||
#[error("Error while parse config file {}: {:#}", path.display(), error)]
|
#[error("Error while parse config file {}: {:#}", path.display(), error)]
|
||||||
Parse {
|
Parse {
|
||||||
error: toml::de::Error,
|
error: toml::de::Error,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -59,4 +59,4 @@ pub enum FetchError {
|
||||||
Feed(#[from] FetchFeedError),
|
Feed(#[from] FetchFeedError),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Hub(#[from] HubError),
|
Hub(#[from] HubError),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
use crate::error::HubError;
|
use crate::error::HubError;
|
||||||
use crate::fetcher::{CacheHeaders, FetchResponse};
|
use crate::fetcher::{CacheHeaders, FetchResponse};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
use reqwest::header::{HeaderValue, USER_AGENT};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
use crate::FETCHER_USER_AGENT;
|
||||||
|
|
||||||
#[instrument(skip(client))]
|
#[instrument(skip(client))]
|
||||||
pub async fn tags(
|
pub async fn tags(
|
||||||
|
|
@ -18,6 +20,7 @@ pub async fn tags(
|
||||||
user, repo
|
user, repo
|
||||||
))
|
))
|
||||||
.headers(cache_headers.headers())
|
.headers(cache_headers.headers())
|
||||||
|
.header(USER_AGENT, HeaderValue::from_static(FETCHER_USER_AGENT))
|
||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,15 @@ use std::future::ready;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::{Duration};
|
use std::time::{Duration};
|
||||||
|
use reqwest::header::{HeaderValue, USER_AGENT};
|
||||||
use syndication::Feed;
|
use syndication::Feed;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::signal::ctrl_c;
|
use tokio::signal::ctrl_c;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use tracing::{debug, error, info, instrument, warn};
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> MainResult {
|
async fn main() -> MainResult {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
@ -192,6 +195,7 @@ impl FeedFetcher {
|
||||||
.client
|
.client
|
||||||
.get(feed)
|
.get(feed)
|
||||||
.headers(cache_headers.headers())
|
.headers(cache_headers.headers())
|
||||||
|
.header(USER_AGENT, HeaderValue::from_static(FETCHER_USER_AGENT))
|
||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue