Skip to content

Commit

Permalink
fix has_manifest for 404 responses - do not evaluate_media_type()
Browse files Browse the repository at this point in the history
If getting a 404 response when calling 'has_manifest' then if the content-type
returned for the json error body is 'application/json; charset=utf-8'
then the call to 'evaluate_media_type' will fail because it does not expect
charset=utf-8 to be valid here. see discussion in:
#113

This change follows the approach taken in other methods above which is to
match on 'status' before continuing.
  • Loading branch information
edwardgeorge committed Sep 11, 2020
1 parent 95eb5a3 commit cf79772
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/v2/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,26 @@ impl Client {
.map_err(Error::from)?;

let status = r.status();
let media_type = evaluate_media_type(r.headers().get(header::CONTENT_TYPE), &r.url())?;

trace!(
"Manifest check status '{:?}', headers '{:?}, media-type: {:?}",
"Manifest check status '{:?}', headers '{:?}",
r.status(),
r.headers(),
media_type
);

let res = match status {
match status {
StatusCode::MOVED_PERMANENTLY
| StatusCode::TEMPORARY_REDIRECT
| StatusCode::FOUND
| StatusCode::OK => Some(media_type),
StatusCode::NOT_FOUND => None,
_ => return Err(Error::UnexpectedHttpStatus(status)),
};
Ok(res)
| StatusCode::OK => {
let media_type =
evaluate_media_type(r.headers().get(header::CONTENT_TYPE), &r.url())?;
trace!("Manifest media-type: {:?}", media_type);
Ok(Some(media_type))
}
StatusCode::NOT_FOUND => Ok(None),
_ => Err(Error::UnexpectedHttpStatus(status)),
}
}
}

Expand Down

0 comments on commit cf79772

Please sign in to comment.