-
Notifications
You must be signed in to change notification settings - Fork 464
Description
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
mediaType = contentType == null || !HttpMediaType.isValid(contentType) ? null : new HttpMediaType(contentType);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.