@Test public void complicatedTextEncodingIssue() throws Exception { String contentType = "text/javascript"; String harContentEncoding = null; String contentEncodingHeaderValue = "br"; String comment = ""; String text = "let nbsp=\"\u00A0\";"; byte[] expectedBytes = text.getBytes(UTF_8); String expectedBytesHex = BaseEncoding.base16().encode(expectedBytes); System.out.format("complicated text: \"%s\"%n", StringEscapeUtils.escapeJava(text)); System.out.format("%s decoded with %s is: %s%n", expectedBytesHex, UTF_8, new String(expectedBytes, UTF_8)); System.out.format("%s decoded with %s is: %s%n", expectedBytesHex, ISO_8859_1, new String(expectedBytes, ISO_8859_1)); long contentSize = expectedBytes.length; long bodySize = expectedBytes.length; @SuppressWarnings("UnnecessaryLocalVariable") Charset EX_MACHINA_CHARSET = UTF_8; @SuppressWarnings("ConstantConditions") TypedContent typedContent = Hars.translateResponseContent(contentType, text, bodySize, contentSize, contentEncodingHeaderValue, harContentEncoding, comment, EX_MACHINA_CHARSET); byte[] actualBytes = typedContent.asByteSource().read(); int actualSize = actualBytes.length; assertEquals("actual size", expectedBytes.length, actualSize); assertEquals("content-type charset", UTF_8, typedContent.getContentType().charset().orNull()); }
public static TypedContent translateResponseContent( String contentType, @Nullable String text, @Nullable Long bodySize, @Nullable Long contentSize, @Nullable String contentEncodingHeaderValue, @Nullable String harContentEncoding, @SuppressWarnings("unused") @Nullable String comment, Charset defaultCharset) { return getUncompressedContent(contentType, text, bodySize, contentSize, contentEncodingHeaderValue, harContentEncoding, comment, defaultCharset); }
Hars { public static TypedContent translateResponseContent( String contentType, @Nullable String text, @Nullable Long bodySize, @Nullable Long contentSize, @Nullable String contentEncodingHeaderValue, @Nullable String harContentEncoding, @SuppressWarnings("unused") @Nullable String comment, Charset defaultCharset) { return getUncompressedContent(contentType, text, bodySize, contentSize, contentEncodingHeaderValue, harContentEncoding, comment, defaultCharset); } }
Hars { public static TypedContent translateResponseContent( String contentType, @Nullable String text, @Nullable Long bodySize, @Nullable Long contentSize, @Nullable String contentEncodingHeaderValue, @Nullable String harContentEncoding, @SuppressWarnings("unused") @Nullable String comment, Charset defaultCharset) { return getUncompressedContent(contentType, text, bodySize, contentSize, contentEncodingHeaderValue, harContentEncoding, comment, defaultCharset); }  }
Hars { public static TypedContent translateResponseContent( String contentType, @Nullable String text, @Nullable Long bodySize, @Nullable Long contentSize, @Nullable String contentEncodingHeaderValue, @Nullable String harContentEncoding, @SuppressWarnings("unused") @Nullable String comment, Charset defaultCharset) { return getUncompressedContent(contentType, text, bodySize, contentSize, contentEncodingHeaderValue, harContentEncoding, comment, defaultCharset); }  static boolean isBase64Encoded(String contentType, String text, @Nullable String harContentEncoding, @Nullable Long bodySize); @Nullable static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset); static TypedContent translateResponseContent(              String contentType,
                                                                      @Nullable String text,
                                                                      @Nullable Long bodySize,
                                                                      @Nullable Long contentSize,
                                                                      @Nullable String contentEncodingHeaderValue,
                                                                      @Nullable String harContentEncoding,
                                                                      @SuppressWarnings("unused") @Nullable String comment,
                                                                      Charset defaultCharset); static HarHeader newHarHeader(String name, String value); }
Hars { public static TypedContent translateResponseContent( String contentType, @Nullable String text, @Nullable Long bodySize, @Nullable Long contentSize, @Nullable String contentEncodingHeaderValue, @Nullable String harContentEncoding, @SuppressWarnings("unused") @Nullable String comment, Charset defaultCharset) { return getUncompressedContent(contentType, text, bodySize, contentSize, contentEncodingHeaderValue, harContentEncoding, comment, defaultCharset); }  static boolean isBase64Encoded(String contentType, String text, @Nullable String harContentEncoding, @Nullable Long bodySize); @Nullable static ByteSource getRequestPostData(@Nullable List<NameValuePair> params, String contentType, String postDataText, @Nullable Long requestBodySize, @Nullable String postDataComment, Charset defaultCharset); static TypedContent translateResponseContent(              String contentType,
                                                                      @Nullable String text,
                                                                      @Nullable Long bodySize,
                                                                      @Nullable Long contentSize,
                                                                      @Nullable String contentEncodingHeaderValue,
                                                                      @Nullable String harContentEncoding,
                                                                      @SuppressWarnings("unused") @Nullable String comment,
                                                                      Charset defaultCharset); static HarHeader newHarHeader(String name, String value);  }