Search in sources :

Example 1 with HTTP_1_1

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;
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) Headers(okhttp3.Headers) ResponseBody(okhttp3.ResponseBody) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Aggregations

Headers (okhttp3.Headers)1 ResponseBody (okhttp3.ResponseBody)1 InputStreamEntity (org.apache.http.entity.InputStreamEntity)1 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)1