From 5b2186817a5769e0f753c0b2f081fd3c3c4f8a35 Mon Sep 17 00:00:00 2001 From: iovxw Date: Wed, 25 Oct 2017 23:03:07 +0800 Subject: [PATCH] Replace link in User-Agent with bot contact link --- src/feed.rs | 13 ++++--------- src/fetcher.rs | 11 ++++++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/feed.rs b/src/feed.rs index 541cab62..cb360650 100644 --- a/src/feed.rs +++ b/src/feed.rs @@ -309,6 +309,7 @@ fn fix_relative_url(mut rss: RSS, rss_link: &str) -> RSS { fn make_request( session: Session, mut source: String, + ua: String, mut recur_limit: usize, ) -> Result<(Vec, String, u32)> { let mut location = None; @@ -325,14 +326,7 @@ fn make_request( req.get(true).unwrap(); req.url(&location.as_ref().unwrap_or(&source)).unwrap(); req.accept_encoding("").unwrap(); // accept all encoding - req.useragent(concat!( - env!("CARGO_PKG_NAME"), - "/", - env!("CARGO_PKG_VERSION"), - " (", - env!("CARGO_PKG_HOMEPAGE"), - ")" - )).unwrap(); + req.useragent(&ua).unwrap(); req.timeout(Duration::from_secs(10)).unwrap(); req.write_function(move |data| { buf.lock().unwrap().extend_from_slice(data); @@ -369,8 +363,9 @@ fn make_request( pub fn fetch_feed<'a>( session: Session, source: String, + ua: String, ) -> impl Future + 'a { - make_request(session, source, 10).and_then(move |(body, mut source, response_code)| { + make_request(session, source, ua, 10).and_then(move |(body, mut source, response_code)| { if response_code != 200 { return Err(ErrorKind::Http(response_code).into()); } diff --git a/src/fetcher.rs b/src/fetcher.rs index 28937c14..c861c206 100644 --- a/src/fetcher.rs +++ b/src/fetcher.rs @@ -83,7 +83,16 @@ fn fetch_feed_updates<'a>( session: Session, feed: data::Feed, ) -> Result<(), ()> { - let rss = match await!(feed::fetch_feed(session, feed.link.to_owned())) { + let ua = format!( + concat!( + env!("CARGO_PKG_NAME"), + "/", + env!("CARGO_PKG_VERSION"), + " (+https://t.me/{})" + ), + bot.inner.username + ); + let rss = match await!(feed::fetch_feed(session, ua, feed.link.to_owned())) { Ok(rss) => rss, Err(e) => { // 1440 * 5 minute = 5 days