http.rs: check response status for fetched images
This patch checks if fetching an image resulted in a non-success status code. In case of non-success status, the response is discarded and an error is emitted. This relies on having 3xx codes already handled by surf's Redirect middleware, so we should see 4xx and 5xx codes here. Fixes hipstermojo/paperoni#11
This commit is contained in:
parent
4581f07330
commit
8ec491ff06
1 changed files with 7 additions and 0 deletions
|
@ -78,6 +78,13 @@ async fn process_img_response<'a>(
|
|||
img_response: &mut surf::Response,
|
||||
url: &'a str,
|
||||
) -> Result<ImgItem<'a>, ImgError> {
|
||||
if !img_response.status().is_success() {
|
||||
let kind = ErrorKind::HTTPError(format!(
|
||||
"Non-success HTTP status code ({})",
|
||||
img_response.status()
|
||||
));
|
||||
return Err(ImgError::with_kind(kind));
|
||||
}
|
||||
let img_content: Vec<u8> = match img_response.body_bytes().await {
|
||||
Ok(bytes) => bytes,
|
||||
Err(e) => return Err(e.into()),
|
||||
|
|
Loading…
Reference in a new issue