use of okhttp3.Protocol.HTTP_1_1 in project okhttp by square.
the class OkApacheClient method transformResponse.
private static HttpResponse transformResponse(Response response) {
int code = response.code();
String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
ResponseBody body = response.body();
InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
httpResponse.setEntity(entity);
Headers headers = response.headers();
for (int i = 0, size = headers.size(); i < size; i++) {
String name = headers.name(i);
String value = headers.value(i);
httpResponse.addHeader(name, value);
if ("Content-Type".equalsIgnoreCase(name)) {
entity.setContentType(value);
} else if ("Content-Encoding".equalsIgnoreCase(name)) {
entity.setContentEncoding(value);
}
}
return httpResponse;
}
Aggregations