@Test public void isTextType() { MediaType[] expectTrue = { MediaType.PLAIN_TEXT_UTF_8, MediaType.JAVASCRIPT_UTF_8, MediaType.TEXT_JAVASCRIPT_UTF_8, MediaType.APPLICATION_XML_UTF_8, MediaType.HTML_UTF_8, MediaType.XHTML_UTF_8, MediaType.CSV_UTF_8, MediaType.CSS_UTF_8, MediaType.XML_UTF_8, MediaType.JSON_UTF_8, }; Stream.of(expectTrue).forEach(ct -> confirmIsTextType(ct, true)); MediaType[] expectFalse = { null, MediaType.PNG, MediaType.JPEG, MediaType.OCTET_STREAM, MediaType.FLV_VIDEO, MediaType.BZIP2, MediaType.MICROSOFT_WORD, MediaType.OPENDOCUMENT_TEXT, }; Stream.of(expectFalse).forEach(ct -> confirmIsTextType(ct, false)); }
protected static boolean isTextType(@Nullable MediaType contentType) { if (contentType == null) { return false; } if (contentType.is(MediaType.ANY_TEXT_TYPE)) { return true; } MediaType noCharsetType = contentType.withoutParameters(); for (MediaType textLike : parameterlessTextLikeTypes) { if (textLike.equals(noCharsetType)) { return true; } } return false; }
ReplacingInterceptor implements ResponseInterceptor { protected static boolean isTextType(@Nullable MediaType contentType) { if (contentType == null) { return false; } if (contentType.is(MediaType.ANY_TEXT_TYPE)) { return true; } MediaType noCharsetType = contentType.withoutParameters(); for (MediaType textLike : parameterlessTextLikeTypes) { if (textLike.equals(noCharsetType)) { return true; } } return false; } }
ReplacingInterceptor implements ResponseInterceptor { protected static boolean isTextType(@Nullable MediaType contentType) { if (contentType == null) { return false; } if (contentType.is(MediaType.ANY_TEXT_TYPE)) { return true; } MediaType noCharsetType = contentType.withoutParameters(); for (MediaType textLike : parameterlessTextLikeTypes) { if (textLike.equals(noCharsetType)) { return true; } } return false; } ReplacingInterceptor(VhsReplayManagerConfig config, Replacement replacement); }
ReplacingInterceptor implements ResponseInterceptor { protected static boolean isTextType(@Nullable MediaType contentType) { if (contentType == null) { return false; } if (contentType.is(MediaType.ANY_TEXT_TYPE)) { return true; } MediaType noCharsetType = contentType.withoutParameters(); for (MediaType textLike : parameterlessTextLikeTypes) { if (textLike.equals(noCharsetType)) { return true; } } return false; } ReplacingInterceptor(VhsReplayManagerConfig config, Replacement replacement); @Override HttpRespondable intercept(ParsedRequest parsedRequest, HttpRespondable httpRespondable); }
ReplacingInterceptor implements ResponseInterceptor { protected static boolean isTextType(@Nullable MediaType contentType) { if (contentType == null) { return false; } if (contentType.is(MediaType.ANY_TEXT_TYPE)) { return true; } MediaType noCharsetType = contentType.withoutParameters(); for (MediaType textLike : parameterlessTextLikeTypes) { if (textLike.equals(noCharsetType)) { return true; } } return false; } ReplacingInterceptor(VhsReplayManagerConfig config, Replacement replacement); @Override HttpRespondable intercept(ParsedRequest parsedRequest, HttpRespondable httpRespondable);  }