Way to workaround invalid Content-Type header in a response?

596 views
Skip to first unread message

Alexander Devine

unread,
May 10, 2013, 12:51:12 PM5/10/13
to google-http...@googlegroups.com
I am attempting to access a server that I realized is sending an invalid Content-Type header. The value it is sending is just "text" instead of "text/plain", which is causing the request to fail with the following stack trace:

Caused by: java.lang.IllegalArgumentException: Type must be in the 'maintype/subtype; parameter=value' format
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:92)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:49)
at com.google.api.client.http.HttpMediaType.fromString(HttpMediaType.java:167)
at com.google.api.client.http.HttpMediaType.<init>(HttpMediaType.java:111)
at com.google.api.client.http.HttpResponse.<init>(HttpResponse.java:157)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:984)
...

Does anyone have an idea if there is a way I could work around this in the client? Since the exception is thrown in the HttpResponse constructor I can't just fix it with an response interceptor.

Thanks,
Alex
Message has been deleted

Steven Benjamin

unread,
Jun 10, 2014, 12:29:52 PM6/10/14
to google-http...@googlegroups.com
Second this - I'm running into the same issue and can't override the HttpMediaType, which has been declared as final. Trying to handle requests that do not have a full set of headers. Is there some way of setting parsing to be more forgiving?

Thanks.
 

Mikael Karlsson

unread,
Jun 27, 2014, 9:32:42 AM6/27/14
to google-http...@googlegroups.com
Did you ever solve this issue? I have the same error in my application, and I can't find a solution for it.

It seems like a bug on the Google side since the download url is given by the Google Drive API, right?

Daniel Wang

unread,
Jan 2, 2015, 11:02:03 AM1/2/15
to google-http...@googlegroups.com
The ultimate solution is obviously to fix the server to return correctly formatted media types. In the current client implementation, there isn't a clean way to override HttpMediaType parsing. However, if you really need it, you can implement your own LowLevelHttpRequest/LowLevelHttpRespone/HttpTransport, where you parse media type more forgivingly. For example, you could return 'Content Type: text/plain' in your LowLevelHttpResponse.getContentType() when you see 'Content Type: text'.

Mikael, did you say that the Google Drive API is returning such a content type?
Reply all
Reply to author
Forward
0 new messages