HTTPClientImpl implements HTTPClient { HTTPResponse response(Response httpResponse) throws IOException { int statusCode = httpResponse.code(); logger.debug("[response] status={}", statusCode); Map<String, String> headers = new TreeMap<>(CASE_INSENSITIVE_ORDER); Headers httpHeaders = httpResponse.headers(); for (int i = 0; i < httpHeaders.size(); i++) { headers.put(httpHeaders.name(i), httpHeaders.value(i)); } logger.debug("[response] headers={}", new FieldMapLogParam(headers)); ResponseBody responseBody = httpResponse.body(); if (responseBody == null) throw new Error("unexpected response body"); byte[] body = responseBody.bytes(); var response = new HTTPResponse(statusCode, headers, body); logger.debug("[response] body={}", BodyLogParam.of(body, response.contentType)); return response; } HTTPClientImpl(OkHttpClient client, String userAgent, Duration slowOperationThreshold); @Override HTTPResponse execute(HTTPRequest request);  }
@Test void response() throws IOException { Response httpResponse = new Response.Builder().request(new Request.Builder().url("http: .protocol(Protocol.HTTP_1_1).code(200).message("OK") .header("content-type", "text/html") .body(ResponseBody.create(Strings.bytes("<html/>"), MediaType.get("text/html"))) .build(); HTTPResponse response = httpClient.response(httpResponse); assertThat(response.statusCode).isEqualTo(200); assertThat(response.contentType.mediaType).isEqualTo(ContentType.TEXT_HTML.mediaType); assertThat(response.headers).containsEntry(HTTPHeaders.CONTENT_TYPE, "text/html"); assertThat(response.text()).isEqualTo("<html/>"); }