HTTPResponse { public String text() { Charset charset = UTF_8; if (contentType != null) charset = contentType.charset().orElse(UTF_8); return new String(body, charset); } HTTPResponse(int statusCode, Map<String, String> headers, byte[] body); String text(); final int statusCode; final byte[] body; final Map<String, String> headers; final ContentType contentType; }
@Test void text() { var response = new HTTPResponse(200, Map.of(HTTPHeaders.CONTENT_TYPE, ContentType.TEXT_PLAIN.toString()), Strings.bytes("value")); assertThat(response.contentType.toString()).isEqualTo(ContentType.TEXT_PLAIN.toString()); assertThat(response.text()).isEqualTo("value"); }