@Test public void replaceContentType() { MediaType originalContentType = MediaType.parse("text/plain"); Iterable<Map.Entry<String, String>> originalHeaders = Collections.singleton(new AbstractMap.SimpleImmutableEntry<>(HttpHeaders.CONTENT_TYPE, originalContentType.toString())); HarResponseData responseData = HarResponseData.of(originalHeaders, originalContentType, null); MediaType newContentType = originalContentType.withCharset(UTF_8); HarResponseData transformed = responseData.transformer() .replaceContentType(newContentType) .transform(); assertEquals("contentType getter", newContentType, transformed.getContentType()); String actualNewContentTypeHeaderValue = transformed.getFirstHeaderValue(HttpHeaders.CONTENT_TYPE); assertNotNull("expect header value present", actualNewContentTypeHeaderValue); assertEquals("header value parsed", newContentType, MediaType.parse(actualNewContentTypeHeaderValue)); }
public HarResponseDataTransformer replaceContentType(MediaType contentType) { return replaceHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()) .contentType(old -> contentType); }
HarResponseDataTransformer { public HarResponseDataTransformer replaceContentType(MediaType contentType) { return replaceHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()) .contentType(old -> contentType); } }
HarResponseDataTransformer { public HarResponseDataTransformer replaceContentType(MediaType contentType) { return replaceHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()) .contentType(old -> contentType); } HarResponseDataTransformer(HarResponseData preTransformData); }
HarResponseDataTransformer { public HarResponseDataTransformer replaceContentType(MediaType contentType) { return replaceHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()) .contentType(old -> contentType); } HarResponseDataTransformer(HarResponseData preTransformData); HarResponseDataTransformer body(Function<ByteSource, ByteSource> bodyTransform); HarResponseDataTransformer contentType(Function<MediaType, MediaType> contentTypeSupplier); HarResponseDataTransformer headers(Function<Stream<Map.Entry<String, String>>, Stream<Map.Entry<String, String>>> headersTransform); HarResponseDataTransformer filterHeaders(Predicate<? super Map.Entry<String, String>> filter); HarResponseDataTransformer mapHeader(Function<Map.Entry<String, String>, Map.Entry<String, String>> map); HarResponseDataTransformer mapHeaderWithName(String headerName, Function<String, String> valueMap); HarResponseDataTransformer replaceHeader(String headerName, String newValue); HarResponseDataTransformer replaceContentType(MediaType contentType); HarResponseData transform(); }
HarResponseDataTransformer { public HarResponseDataTransformer replaceContentType(MediaType contentType) { return replaceHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()) .contentType(old -> contentType); } HarResponseDataTransformer(HarResponseData preTransformData); HarResponseDataTransformer body(Function<ByteSource, ByteSource> bodyTransform); HarResponseDataTransformer contentType(Function<MediaType, MediaType> contentTypeSupplier); HarResponseDataTransformer headers(Function<Stream<Map.Entry<String, String>>, Stream<Map.Entry<String, String>>> headersTransform); HarResponseDataTransformer filterHeaders(Predicate<? super Map.Entry<String, String>> filter); HarResponseDataTransformer mapHeader(Function<Map.Entry<String, String>, Map.Entry<String, String>> map); HarResponseDataTransformer mapHeaderWithName(String headerName, Function<String, String> valueMap); HarResponseDataTransformer replaceHeader(String headerName, String newValue); HarResponseDataTransformer replaceContentType(MediaType contentType); HarResponseData transform();  }