private static void consumeContentQuietly(HttpResponse response) { try { response.getEntity().consumeContent(); } catch (Throwable ignored) { } } }
@Override public String getContentEncoding() { return (response == null || response.getEntity() == null || response.getEntity().getContentEncoding() == null) ? null : response.getEntity().getContentEncoding().getValue(); }
@Override public String getStatusText() throws IOException { return this.httpResponse.getStatusLine().getReasonPhrase(); }
@Override public int getRawStatusCode() throws IOException { return this.httpResponse.getStatusLine().getStatusCode(); }
@Override public InputStream getInputStream() throws IOException { return response == null || response.getEntity() == null ? null : response.getEntity().getContent(); }
@Override public HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); for (Header header : this.httpResponse.getAllHeaders()) { this.headers.add(header.getName(), header.getValue()); } } return this.headers; }
/** * Determine whether the given response indicates a GZIP response. * <p>The default implementation checks whether the HTTP "Content-Encoding" * header contains "gzip" (in any casing). * @param httpResponse the resulting HttpResponse to check * @return whether the given response indicates a GZIP response */ protected boolean isGzipResponse(HttpResponse httpResponse) { Header encodingHeader = httpResponse.getFirstHeader(HTTP_HEADER_CONTENT_ENCODING); return (encodingHeader != null && encodingHeader.getValue() != null && encodingHeader.getValue().toLowerCase().contains(ENCODING_GZIP)); }
HttpEntityBody(HttpEntity entity, String contentTypeHeader) { this.entity = entity; if (contentTypeHeader != null) { mediaType = MediaType.parse(contentTypeHeader); } else if (entity.getContentType() != null) { mediaType = MediaType.parse(entity.getContentType().getValue()); } else { // Apache is forgiving and lets you skip specifying a content type with an entity. OkHttp is // not forgiving so we fall back to a generic type if it's missing. mediaType = DEFAULT_MEDIA_TYPE; } }
@Override public long contentLength() { return entity.getContentLength(); }
@Override public int getRawStatusCode() throws IOException { return this.httpResponse.getStatusLine().getStatusCode(); }
@Override public InputStream getInputStream() throws IOException { return response == null || response.getEntity() == null ? null : response.getEntity().getContent(); }
@Override public String getStatusText() throws IOException { return this.httpResponse.getStatusLine().getReasonPhrase(); }
@Override public String getContentEncoding() { return (response == null || response.getEntity() == null || response.getEntity().getContentEncoding() == null) ? null : response.getEntity().getContentEncoding().getValue(); }
@Override public HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); for (Header header : this.httpResponse.getAllHeaders()) { this.headers.add(header.getName(), header.getValue()); } } return this.headers; }
@Override public int getStatusCode() { return response == null || response.getStatusLine() == null ? 0 : response.getStatusLine().getStatusCode(); }
@Override public InputStream getBody() throws IOException { HttpEntity entity = this.httpResponse.getEntity(); return (entity != null ? entity.getContent() : StreamUtils.emptyInput()); }
@Override public String getStatusMessage() { return response == null || response.getStatusLine() == null ? null : response.getStatusLine().getReasonPhrase(); }
@Override public int getStatusCode() { return response == null || response.getStatusLine() == null ? 0 : response.getStatusLine().getStatusCode(); }
@Override public InputStream getBody() throws IOException { HttpEntity entity = this.httpResponse.getEntity(); return (entity != null ? entity.getContent() : StreamUtils.emptyInput()); }
@Override public String getStatusMessage() { return response == null || response.getStatusLine() == null ? null : response.getStatusLine().getReasonPhrase(); }