AcmeUtils { @Nullable public static String getContentType(@Nullable String header) { if (header != null) { Matcher m = CONTENT_TYPE_PATTERN.matcher(header); if (m.matches()) { String charset = m.group(3); if (charset != null && !"utf-8".equalsIgnoreCase(charset)) { throw new AcmeProtocolException("Unsupported charset " + charset); } return m.group(1).trim().toLowerCase(); } } return null; } private  AcmeUtils(); static byte[] sha256hash(String z); static String hexEncode(byte[] data); static String base64UrlEncode(byte[] data); static byte[] base64UrlDecode(String base64); static boolean isValidBase64Url(@Nullable String base64); static String toAce(String domain); static Instant parseTimestamp(String str); @Nullable static String stripErrorPrefix(@Nullable String type); static void writeToPem(byte[] encoded, PemLabel label, Writer out); @Nullable static String getContentType(@Nullable String header); static void validateContact(URI contact);  }
@Test public void testGetContentType() { assertThat(AcmeUtils.getContentType(null), is(nullValue())); assertThat(AcmeUtils.getContentType("application/json"), is("application/json")); assertThat(AcmeUtils.getContentType("Application/Problem+JSON"), is("application/problem+json")); assertThat(AcmeUtils.getContentType("application/json; charset=utf-8"), is("application/json")); assertThat(AcmeUtils.getContentType("application/json; charset=utf-8 (Plain text)"), is("application/json")); assertThat(AcmeUtils.getContentType("application/json; charset=\"utf-8\""), is("application/json")); assertThat(AcmeUtils.getContentType("application/json; charset=\"UTF-8\"; foo=4"), is("application/json")); assertThat(AcmeUtils.getContentType(" application/json ;foo=4"), is("application/json")); try { AcmeUtils.getContentType("application/json; charset=\"iso-8859-1\""); fail("Accepted bad charset"); } catch (AcmeProtocolException ex) { } }