Merge branch 'alatiera/source-redirects-85' into 'master'
Source: Improve http redirections handling Closes #85 See merge request World/podcasts!62
This commit is contained in:
commit
1e0a919dc7
@ -145,13 +145,15 @@ impl Source {
|
|||||||
|
|
||||||
match code {
|
match code {
|
||||||
StatusCode::NotModified => return Err(self.make_err("304: skipping..", code)),
|
StatusCode::NotModified => return Err(self.make_err("304: skipping..", code)),
|
||||||
StatusCode::MovedPermanently => {
|
StatusCode::MovedPermanently | StatusCode::Found | StatusCode::PermanentRedirect => {
|
||||||
error!("Feed was moved permanently.");
|
error!("Feed was moved permanently.");
|
||||||
self = self.update_url(&res)?;
|
self = self.update_url(&res)?;
|
||||||
return Err(DataError::F301(self));
|
return Err(DataError::F301(self));
|
||||||
}
|
}
|
||||||
StatusCode::TemporaryRedirect => debug!("307: Temporary Redirect."),
|
StatusCode::TemporaryRedirect => {
|
||||||
StatusCode::PermanentRedirect => warn!("308: Permanent Redirect."),
|
debug!("307: Temporary Redirect.");
|
||||||
|
return Err(DataError::F301(self));
|
||||||
|
}
|
||||||
StatusCode::Unauthorized => return Err(self.make_err("401: Unauthorized.", code)),
|
StatusCode::Unauthorized => return Err(self.make_err("401: Unauthorized.", code)),
|
||||||
StatusCode::Forbidden => return Err(self.make_err("403: Forbidden.", code)),
|
StatusCode::Forbidden => return Err(self.make_err("403: Forbidden.", code)),
|
||||||
StatusCode::NotFound => return Err(self.make_err("404: Not found.", code)),
|
StatusCode::NotFound => return Err(self.make_err("404: Not found.", code)),
|
||||||
@ -164,13 +166,20 @@ impl Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_url(mut self, res: &Response) -> Result<Self, DataError> {
|
fn update_url(mut self, res: &Response) -> Result<Self, DataError> {
|
||||||
|
let code = res.status();
|
||||||
let headers = res.headers();
|
let headers = res.headers();
|
||||||
|
info!("HTTP StatusCode: {}", code);
|
||||||
|
debug!("Headers {:#?}", headers);
|
||||||
|
|
||||||
if let Some(url) = headers.get::<Location>() {
|
if let Some(url) = headers.get::<Location>() {
|
||||||
|
debug!("Previous Source: {:#?}", &self);
|
||||||
|
|
||||||
self.set_uri(url.to_string());
|
self.set_uri(url.to_string());
|
||||||
self = self.save()?;
|
self = self.save()?;
|
||||||
info!("Feed url was updated succesfully.");
|
|
||||||
self = self.clear_etags()?;
|
self = self.clear_etags()?;
|
||||||
|
|
||||||
|
debug!("Updated Source: {:#?}", &self);
|
||||||
|
info!("Feed url of Source {}, was updated succesfully.", self.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user