Broken implementation of etag/last_mod request.
This commit is contained in:
parent
d76d367a9c
commit
e1cc4f0d9f
@ -10,6 +10,7 @@ structopt-derive = "0.1.0"
|
||||
log = "0.3.8"
|
||||
loggerv = "0.3.0"
|
||||
reqwest = "0.7.3"
|
||||
hyper = "0.11.2"
|
||||
diesel = { version = "0.16.0", features = ["sqlite", "deprecated-time", "chrono"] }
|
||||
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
|
||||
time = "0.1.38"
|
||||
|
||||
@ -119,19 +119,40 @@ pub fn index_loop(db: &SqliteConnection) -> Result<()> {
|
||||
}
|
||||
|
||||
// TODO: make it into an iterator that yields reqwest::response
|
||||
// TODO: After fixing etag/lmod, add sent_etag:bool arg and logic to bypass it.
|
||||
pub fn fetch_feeds(connection: &SqliteConnection) -> Result<Vec<(reqwest::Response, Source)>> {
|
||||
use reqwest::header::{ETag, EntityTag, Headers, HttpDate, LastModified};
|
||||
|
||||
let mut results = Vec::new();
|
||||
|
||||
let mut feeds = dbqueries::get_sources(connection)?;
|
||||
|
||||
for feed in feeds.iter_mut() {
|
||||
// TODO sent etag headers
|
||||
let req = reqwest::get(feed.uri())?;
|
||||
let client = reqwest::Client::new()?;
|
||||
let mut headers = Headers::new();
|
||||
|
||||
// TODO match on status()
|
||||
if req.status() == reqwest::StatusCode::NotModified {
|
||||
continue;
|
||||
if let Some(foo) = feed.http_etag() {
|
||||
headers.set(ETag(EntityTag::new(true, foo.to_owned())));
|
||||
}
|
||||
|
||||
if let Some(foo) = feed.last_modified() {
|
||||
headers.set(LastModified(foo.parse::<HttpDate>()?));
|
||||
}
|
||||
|
||||
info!("{:?}", headers);
|
||||
// FIXME: I have fucked up something here.
|
||||
// Getting back 200 codes even though I supposedly sent etags.
|
||||
let req = client.get(feed.uri())?.headers(headers).send()?;
|
||||
info!("{}", req.status());
|
||||
|
||||
// TODO match on more stuff
|
||||
match req.status() {
|
||||
reqwest::StatusCode::NotModified => {
|
||||
continue;
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
feed.update_etag(connection, &req)?;
|
||||
results.push((req, feed.clone()));
|
||||
}
|
||||
|
||||
@ -20,8 +20,10 @@ extern crate diesel;
|
||||
extern crate diesel_codegen;
|
||||
|
||||
extern crate chrono;
|
||||
extern crate hyper;
|
||||
extern crate reqwest;
|
||||
extern crate rss;
|
||||
extern crate time;
|
||||
extern crate xdg;
|
||||
|
||||
pub mod cli;
|
||||
@ -37,6 +39,8 @@ pub mod errors {
|
||||
use std::io;
|
||||
use rss;
|
||||
use chrono;
|
||||
use hyper;
|
||||
use time;
|
||||
use diesel::migrations::RunMigrationsError;
|
||||
use diesel::result;
|
||||
|
||||
@ -49,6 +53,8 @@ pub mod errors {
|
||||
RSSError(rss::Error);
|
||||
DieselResultError(result::Error);
|
||||
ChronoError(chrono::ParseError);
|
||||
DurationError(time::OutOfRangeError);
|
||||
HyperError(hyper::error::Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user