@Override public HttpEntity getEntity() { return original.getEntity(); }
@Override public StatusLine getStatusLine() { return original.getStatusLine(); }
@Override public HttpResponse receiveResponseHeader() throws HttpException, IOException { final HttpResponse response = super.receiveResponseHeader(); if (log.isDebugEnabled()) { log.debug("Receiving response: " + response.getStatusLine()); } if (headerLog.isDebugEnabled()) { headerLog.debug("<< " + response.getStatusLine().toString()); final Header[] headers = response.getAllHeaders(); for (final Header header : headers) { headerLog.debug("<< " + header.toString()); } } return response; }
private void ensure304DoesNotContainExtraEntityHeaders(final HttpResponse response) { final String[] disallowedEntityHeaders = { HeaderConstants.ALLOW, HTTP.CONTENT_ENCODING, "Content-Language", HTTP.CONTENT_LEN, "Content-MD5", "Content-Range", HTTP.CONTENT_TYPE, HeaderConstants.LAST_MODIFIED }; if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED) { for(final String hdr : disallowedEntityHeaders) { response.removeHeaders(hdr); } } }
@Override public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { Args.notNull(response, "HTTP response"); if (!response.containsHeader(HTTP.SERVER_HEADER)) { if (this.originServer != null) { response.addHeader(HTTP.SERVER_HEADER, this.originServer); } } }
private void ensure206ContainsDateHeader(final HttpResponse response) { if (response.getFirstHeader(HTTP.DATE_HEADER) == null) { response.addHeader(HTTP.DATE_HEADER, DateUtils.formatDate(new Date())); } }
protected String loadUrlBody(String address) { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = null; String responseString = null; try { response = httpclient.execute(new HttpGet(address)); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); } else{ response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { } catch (IOException e) { } return responseString; }
final int status = response.getStatusLine().getStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine()); this.log.debug("Connection kept alive"); final HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } else { final int status = response.getStatusLine().getStatusCode(); final HttpEntity entity = response.getEntity(); if (entity != null) { response.setEntity(new BufferedHttpEntity(entity)); response.getStatusLine(), response);
Args.notNull(response, "HTTP response"); if (this.overwrite) { response.removeHeaders(HTTP.TRANSFER_ENCODING); response.removeHeaders(HTTP.CONTENT_LEN); } else { if (response.containsHeader(HTTP.TRANSFER_ENCODING)) { throw new ProtocolException("Transfer-encoding header already present"); if (response.containsHeader(HTTP.CONTENT_LEN)) { throw new ProtocolException("Content-Length header already present"); final ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); final HttpEntity entity = response.getEntity(); if (entity != null) { final long len = entity.getContentLength(); if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) { response.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING); } else if (len >= 0) { response.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength())); if (entity.getContentType() != null && !response.containsHeader( HTTP.CONTENT_TYPE )) { response.addHeader(entity.getContentType()); if (entity.getContentEncoding() != null && !response.containsHeader( HTTP.CONTENT_ENCODING)) { response.addHeader(entity.getContentEncoding()); final int status = response.getStatusLine().getStatusCode();
StatusLine statusLine = httpResponse.getStatusLine(); result.statusLine = statusLine.toString(); result.setStatusCode(statusLine.getStatusCode()); case OK: case UNKNOWN: HttpEntity entity = httpResponse.getEntity(); if (entity != null) { if (result.fileResult != null) { result.appendToLog( "statusLine:'" + statusLine + "'"); result.redirected = true; final Header[] locations = httpResponse.getHeaders("Location"); final String location = locations != null && locations.length > 0 ? locations[0].getValue() : ""; stop = StringUtils.isEmpty(location); for (Header header: httpResponse.getAllHeaders()) { message.append(header.getName() +": " + header.getValue() + ";\n"); default: result.appendToLog( "statusLine:'" + statusLine + "'"); entity = httpResponse.getEntity(); if (entity != null) { result.strResponse = HttpConnectionUtils.readStreamToString(entity.getContent());
final int status = response.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_REQUEST_TIMEOUT || status == HttpStatus.SC_SERVICE_UNAVAILABLE || status == HttpStatus.SC_NOT_IMPLEMENTED) { response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE); return; final Header explicit = response.getFirstHeader(HTTP.CONN_DIRECTIVE); if (explicit != null && HTTP.CONN_CLOSE.equalsIgnoreCase(explicit.getValue())) { final HttpEntity entity = response.getEntity(); if (entity != null) { final ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); if (entity.getContentLength() < 0 && (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0))) { response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE); return; final Header header = request.getFirstHeader(HTTP.CONN_DIRECTIVE); if (header != null) { response.setHeader(HTTP.CONN_DIRECTIVE, header.getValue()); } else if (request.getProtocolVersion().lessEquals(HttpVersion.HTTP_1_0)) { response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
response.setParams(this.params); this.requestExec.postProcess(response, this.httpProcessor, context); final int status = response.getStatusLine().getStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine()); this.log.debug("Connection kept alive"); final HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } else { final int status = response.getStatusLine().getStatusCode(); final HttpEntity entity = response.getEntity(); if (entity != null) { response.setEntity(new BufferedHttpEntity(entity)); response.getStatusLine(), response);
final int status = response.getStatusLine().getStatusCode(); if (cacheableStatuses.contains(status)) { final Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN); if (contentLength != null) { final int contentLengthValue = Integer.parseInt(contentLength.getValue()); final Header[] ageHeaders = response.getHeaders(HeaderConstants.AGE); final Header[] expiresHeaders = response.getHeaders(HeaderConstants.EXPIRES); final Header[] dateHeaders = response.getHeaders(HTTP.DATE_HEADER); for (final Header varyHdr : response.getHeaders(HeaderConstants.VARY)) { for (final HeaderElement elem : varyHdr.getElements()) { if ("*".equals(elem.getName())) {
boolean isIncompleteResponse(final HttpResponse resp, final Resource resource) { final int status = resp.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_OK && status != HttpStatus.SC_PARTIAL_CONTENT) { return false; } final Header hdr = resp.getFirstHeader(HTTP.CONTENT_LEN); if (hdr == null) { return false; } final int contentLength; try { contentLength = Integer.parseInt(hdr.getValue()); } catch (final NumberFormatException nfe) { return false; } if (resource == null) { return false; } return (resource.length() < contentLength); }
@Override public void process( final HttpResponse response, final HttpContext context) throws HttpException, IOException { final HttpEntity entity = response.getEntity(); final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig requestConfig = clientContext.getRequestConfig(); // entity can be null in case of 304 Not Modified, 204 No Content or similar // check for zero length entity. if (requestConfig.isDecompressionEnabled() && entity != null && entity.getContentLength() != 0) { final Header ceheader = entity.getContentEncoding(); if (ceheader != null) { final HeaderElement[] codecs = ceheader.getElements(); for (final HeaderElement codec : codecs) { final String codecname = codec.getName().toLowerCase(Locale.ROOT); final InputStreamFactory decoderFactory = decoderRegistry.lookup(codecname); if (decoderFactory != null) { response.setEntity(new DecompressingEntity(response.getEntity(), decoderFactory)); response.removeHeaders("Content-Length"); response.removeHeaders("Content-Encoding"); response.removeHeaders("Content-MD5"); } else { if (!"identity".equals(codecname)) { throw new HttpException("Unsupported Content-Coding: " + codec.getName()); } } } } } }
@Override public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { Args.notNull(response, "HTTP response"); final int status = response.getStatusLine().getStatusCode(); if ((status >= HttpStatus.SC_OK) && !response.containsHeader(HTTP.DATE_HEADER)) { final String httpdate = DATE_GENERATOR.getCurrentDate(); response.setHeader(HTTP.DATE_HEADER, httpdate); } }
private void ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero(final HttpRequest request, final HttpResponse response) { if (!request.getRequestLine().getMethod().equalsIgnoreCase(HeaderConstants.OPTIONS_METHOD)) { return; } if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { return; } if (response.getFirstHeader(HTTP.CONTENT_LEN) == null) { response.addHeader(HTTP.CONTENT_LEN, "0"); } }
response.setParams(params); requestExec.postProcess(response, httpProcessor, context); if (reuse) { final HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); if ((response == null) || (response.getEntity() == null) || !response.getEntity().isStreaming()) { } else { HttpEntity entity = response.getEntity(); entity = new BasicManagedEntity(entity, managedConn, reuse); response.setEntity(entity);
contentEncodingInterceptor.process(response, localContext); if (Boolean.TRUE.equals(localContext.getAttribute(ResponseContentEncoding.UNCOMPRESSED))) { response.removeHeaders("Content-Length"); response.removeHeaders("Content-Encoding"); response.removeHeaders("Content-MD5"); EntityUtils.consume(response.getEntity()); throw ex; } catch (final IOException ex) { EntityUtils.consume(response.getEntity()); throw ex; } catch (final RuntimeException ex) { EntityUtils.consume(response.getEntity()); throw ex;