Source: Set Etag and last modified to None upon redirect.

This commit is contained in:
Jordan Petridis 2018-02-01 19:35:35 +02:00
parent 7b62ef203d
commit 80fd4e9fc5
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -110,6 +110,7 @@ impl Source {
// 408: Timeout // 408: Timeout
// 410: Feed deleted // 410: Feed deleted
fn match_status(mut self, res: Response) -> Result<(Self, Response)> { fn match_status(mut self, res: Response) -> Result<(Self, Response)> {
self.update_etag(&res)?;
let code = res.status(); let code = res.status();
match code { match code {
StatusCode::NotModified => bail!("304: skipping.."), StatusCode::NotModified => bail!("304: skipping.."),
@ -135,6 +136,8 @@ impl Source {
if let Some(url) = headers.get::<Location>() { if let Some(url) = headers.get::<Location>() {
self.set_uri(url.to_string()); self.set_uri(url.to_string());
self.http_etag = None;
self.last_modified = None;
self.save()?; self.save()?;
info!("Feed url was updated succesfully."); info!("Feed url was updated succesfully.");
// TODO: Refresh in place instead of next time, Not a priority. // TODO: Refresh in place instead of next time, Not a priority.
@ -169,11 +172,7 @@ impl Source {
) -> Box<Future<Item = Feed, Error = Error>> { ) -> Box<Future<Item = Feed, Error = Error>> {
let id = self.id(); let id = self.id();
let feed = self.request_constructor(client, ignore_etags) let feed = self.request_constructor(client, ignore_etags)
.and_then(move |(mut source, res)| { .and_then(move |(_, res)| response_to_channel(res, pool))
source.update_etag(&res)?;
Ok(res)
})
.and_then(move |res| response_to_channel(res, pool))
.and_then(move |chan| { .and_then(move |chan| {
FeedBuilder::default() FeedBuilder::default()
.channel(chan) .channel(chan)
@ -213,6 +212,7 @@ impl Source {
let work = client let work = client
.request(req) .request(req)
.map_err(From::from) .map_err(From::from)
// TODO: tail recursion loop that would follow redirects directly
.and_then(move |res| self.match_status(res)); .and_then(move |res| self.match_status(res));
Box::new(work) Box::new(work)
} }