Skip to content

WebResponse.getContentAsString() fails to handle brotli stream data #175

@RuralHunter

Description

@RuralHunter

This is the test case to show the problem, most of it is copied from WebResponseDataTest:

@Test
    public void testWebResponse() throws Exception
    {
        final InputStream stream = getClass().getClassLoader().getResourceAsStream("testfiles/test.html.brotli");
        final byte[] zippedContent = IOUtils.toByteArray(stream);

        final List<com.gargoylesoftware.htmlunit.util.NameValuePair> headers = new ArrayList<>();
        headers.add(new com.gargoylesoftware.htmlunit.util.NameValuePair("Content-Encoding", "br"));

        final WebResponseData data = new WebResponseData(zippedContent, HttpStatus.SC_OK, "OK", headers);
        WebResponse response=new WebResponse(data,new URL("http://test.com"),HttpMethod.GET,1000);
        logger.info("content string:{}", response.getContentAsString());
        logger.info("body:{}", new String(data.getBody(), UTF_8));
    }

Just compare the output of the last 2 lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions