Skip to content

Commit

Permalink
Replace link in User-Agent with bot contact link
Browse files Browse the repository at this point in the history
  • Loading branch information
iovxw committed Oct 25, 2017
1 parent b872837 commit 5b21868
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, String, u32)> {
let mut location = None;
Expand All @@ -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);
Expand Down Expand Up @@ -369,8 +363,9 @@ fn make_request(
pub fn fetch_feed<'a>(
session: Session,
source: String,
ua: String,
) -> impl Future<Item = RSS, Error = Error> + '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());
}
Expand Down
11 changes: 10 additions & 1 deletion src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b21868

Please sign in to comment.