HttpClient { static MediaType parseContentType(final Response response) throws IOException { final String contentType = response.header("Content-Type"); if (contentType == null) { return null; } try { return MediaType.parse(contentType); } catch (IllegalArgumentException e) { throw new IOException("Failed to parse Content-Type header " + contentType, e); } } HttpClient(OkHttpClient okHttpClient); static HttpClient newHttpClient(); static HttpClient newHttpClient(OkHttpClient okHttpClient); void get(URI uri, Path output, Map<String, ? extends Credentials> credentials, HttpTransferListener listener); InputStream get(URI uri, Map<String, ? extends Credentials> credentials, HttpTransferListener listener); void partialGet(URI uri, List<ContentRange> ranges, Map<String, ? extends Credentials> credentials,
      RangeReceiver receiver, RangeTransferListener listener);  }
@Test public void testParseContentTypeNull() throws IOException { final Response response = fakeResponse(HTTP_OK); assertNull(parseContentType(response)); }
@Test(expected = IOException.class) public void testParseContentTypeInvalid() throws IOException { final Response response = fakeResponse(HTTP_OK).newBuilder().addHeader("Content-Type", "bla").build(); parseContentType(response); }
@Test public void testParseContentTypeMultipart() throws IOException { final Response response = fakeResponse(HTTP_OK).newBuilder() .addHeader("Content-Type", "multipart/byteranges;boundary=gc0p4Jq0M2Yt08jU534c0p").build(); assertEquals( MediaType.create("multipart", "byteranges").withParameters( ImmutableMultimap.of("boundary", "gc0p4Jq0M2Yt08jU534c0p")), parseContentType(response)); }