@Override public String getContentEncoding() { return (response == null || response.getEntity() == null || response.getEntity().getContentEncoding() == null) ? null : response.getEntity().getContentEncoding().getValue(); }
@Override public String getContentEncoding() { return (response == null || response.getEntity() == null || response.getEntity().getContentEncoding() == null) ? null : response.getEntity().getContentEncoding().getValue(); }
public Header getContentEncoding() { return wrappedEntity.getContentEncoding(); }
private String getEncoding(HttpEntity entity){ if(entity == null) return null; Header eheader = entity.getContentEncoding(); if(eheader == null) return null; return eheader.getValue(); }
private static void appendHttpEntity(StringBuilder sb, HttpEntity e) { try { InputStream is = e.getContent(); String encoding = e.getContentEncoding().getValue(); System.out.println(encoding); BufferedReader br = new BufferedReader(new InputStreamReader(is, Charset.forName(encoding))); String str = null; while ((str = br.readLine()) != null) { sb.append(str); } br.close(); } catch (IOException ex) { LOG.severe(ex.getMessage()); } }
Header encoding = entity.getContentEncoding(); if (encoding != null) { builder.header(encoding.getName(), encoding.getValue());
protected boolean hasEncoding( final HttpResponse response, final String encoding ) { HttpEntity entity = response.getEntity(); if ( entity == null ) return false; Header ceHeader = entity.getContentEncoding(); if ( ceHeader == null ) return false; HeaderElement[] codecs = ceHeader.getElements(); for ( int i = 0; i < codecs.length; i++ ) if ( encoding.equalsIgnoreCase( codecs[i].getName() ) ) return true; return false; } }
public static InputStream getUngzippedContent(HttpEntity entity) throws IOException { InputStream responseStream = entity.getContent(); if (responseStream == null) return null; Header header = entity.getContentEncoding(); if (header == null) return responseStream; String contentEncoding = header.getValue(); if (contentEncoding == null) return responseStream; if (contentEncoding.contains("gzip")) { Timber.i("Response is gzipped"); responseStream = new GZIPInputStream(responseStream); } return responseStream; }
/** * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an * {@link HttpEntity}. The encoding is taken from the entity's * Content-Encoding header. * <p> * This is typically used while parsing an HTTP POST. * * @param entity * The entity to parse * @throws IOException * If there was an exception getting the entity's data. */ public static List <NameValuePair> parse ( final HttpEntity entity) throws IOException { List <NameValuePair> result = Collections.emptyList(); if (isEncoded(entity)) { final String content = EntityUtils.toString(entity); final Header encoding = entity.getContentEncoding(); if (content != null && content.length() > 0) { result = new ArrayList <NameValuePair>(); parse(result, new Scanner(content), encoding != null ? encoding.getValue() : null); } } return result; }
/** * Loads the content of this page from a fetched HttpEntity. * * @param entity HttpEntity * @param maxBytes The maximum number of bytes to read * @throws IOException when load fails */ public void load(HttpEntity entity, int maxBytes) throws IOException { contentType = null; Header type = entity.getContentType(); if (type != null) { contentType = type.getValue(); } contentEncoding = null; Header encoding = entity.getContentEncoding(); if (encoding != null) { contentEncoding = encoding.getValue(); } Charset charset; try { charset = ContentType.getOrDefault(entity).getCharset(); } catch (Exception e) { logger.warn("parse charset failed: {}", e.getMessage()); charset = Charset.forName("UTF-8"); } if (charset != null) { contentCharset = charset.displayName(); } contentData = toByteArray(entity, maxBytes); }
@Override public void process(final HttpResponse response, final HttpContext context) { // Inflate any responses compressed with gzip final HttpEntity entity = response.getEntity(); if (entity != null) { final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(IgnitedHttp.ENCODING_GZIP)) { response.setEntity(new GzipInflatingEntity(response.getEntity())); break; } } } } }
/** * Set the transfer, content encodings based on headers (if necessary). * * @param rec * Recorder for this request. * @param response * Method used for the request. */ protected void setOtherCodings(CrawlURI uri, final Recorder rec, final HttpResponse response) { if (response.getEntity() != null) { rec.setInputIsChunked(response.getEntity().isChunked()); Header contentEncodingHeader = response.getEntity().getContentEncoding(); if (contentEncodingHeader != null) { String ce = contentEncodingHeader.getValue().trim(); try { rec.setContentEncoding(ce); } catch (IllegalArgumentException e) { uri.getAnnotations().add("unsatisfiableContentEncoding:" + StringUtils.stripToEmpty(ce)); } } } }
try { InputStream responseInputStream = responseEntity.getContent(); if (ResponseUtils.isGzipped(responseEntity.getContentEncoding())) { responseInputStream = new GZIPInputStream(responseEntity.getContent());
final Header contentEncoding = entity.getContentEncoding(); if (headers.get(HttpHeaders.CONTENT_ENCODING) == null && contentEncoding != null) { headers.add(HttpHeaders.CONTENT_ENCODING, contentEncoding.getValue());
if (entity.getContentEncoding() != null && !response.containsHeader( HTTP.CONTENT_ENCODING)) { response.addHeader(entity.getContentEncoding());
if (entity.getContentEncoding() != null && !request.containsHeader( HTTP.CONTENT_ENCODING)) { request.addHeader(entity.getContentEncoding());
protected boolean hasEncoding( final HttpResponse response, final String encoding ) { HttpEntity entity = response.getEntity(); if ( entity == null ) return false; Header ceHeader = entity.getContentEncoding(); if ( ceHeader == null ) return false; HeaderElement[] codecs = ceHeader.getElements(); for ( int i = 0; i < codecs.length; i++ ) if ( encoding.equalsIgnoreCase( codecs[i].getName() ) ) return true; return false; } }
httpclient.addResponseInterceptor(new HttpResponseInterceptor() { public void process( final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); Header ceheader = entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity( new GzipDecompressingEntity(response.getEntity())); return; } } } } });
mHttpClient.addResponseInterceptor(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); Header encheader = entity.getContentEncoding(); if (encheader != null) { HeaderElement[] codecs = encheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity( entity)); return; } } } } });
public AwsProxyRequestBuilder formFilePart(String fieldName, String fileName, byte[] content) throws IOException { if (multipartBuilder == null) { multipartBuilder = MultipartEntityBuilder.create(); } multipartBuilder.addPart(fieldName, new ByteArrayBody(content, fileName)); HttpEntity bodyEntity = multipartBuilder.build(); InputStream bodyStream = bodyEntity.getContent(); byte[] buffer = new byte[bodyStream.available()]; IOUtils.readFully(bodyStream, buffer); request.setBody("\n\n" + new String(buffer, Charset.defaultCharset())); if (request.getMultiValueHeaders() == null) { request.setMultiValueHeaders(new Headers()); } request.getMultiValueHeaders().putSingle(HttpHeaders.CONTENT_TYPE, bodyEntity.getContentType().getValue()); if (bodyEntity.getContentEncoding() != null) { request.getMultiValueHeaders().putSingle(HttpHeaders.CONTENT_ENCODING, bodyEntity.getContentEncoding().getValue()); } request.getMultiValueHeaders().putSingle(HttpHeaders.CONTENT_LENGTH, bodyEntity.getContentLength() + ""); return this; }