InvalidArgumentException from HttpResponse if the content-type is invalid #905
Labels
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
I'm hitting an edge case at HttpResponse.java#153: if the contentType of the response is invalid, an InvalidArgumentException is thrown while constructing the media type. My code makes an http request to read the contents of a file from Google Cloud Storage, so if the owner of the file has set an invalid content-type (which is easy to do in GCS, unfortunately), I can't read the file at all.
I understand that this might just be WAI, and I could just throw the error back to the user, however it would be nice if I could handle this gracefully and read the file contents as if the mediaType were unknown. It's difficult for me to catch and handle the error myself since I'm not calling this library directly (another library that I don't own is making the http request).
Since mediaType is nullable anyway, would it be reasonable behavior to set it to null if the contentType were invalid? Something like
where isValid would return true iff the contentType can be parsed to a valid mediaType.
Would this be an okay change? I wanted to check before actually sending a pull request. Thanks.
The text was updated successfully, but these errors were encountered: