@Override public Header getContentType() { return wrappedEntity.getContentType(); }
@Override public Header getContentType() { return original.getContentType(); }
public String getContentType() { if (entity == null) { return null; } Header header = entity.getContentType(); if (header == null) { return null; } return header.getValue(); }
/** * Returns true if the entity's Content-Type header is * {@code application/x-www-form-urlencoded}. */ public static boolean isEncoded(final HttpEntity entity) { final Header h = entity.getContentType(); if (h != null) { final HeaderElement[] elems = h.getElements(); if (elems.length > 0) { final String contentType = elems[0].getName(); return contentType.equalsIgnoreCase(CONTENT_TYPE); } } return false; }
/** * Obtains MIME type of the entity, if known. * * @param entity must not be null * @return the character set, or null if not found * @throws ParseException if header elements cannot be parsed * @throws IllegalArgumentException if entity is null * * @since 4.1 * * @deprecated (4.1.3) use {@link ContentType#getOrDefault(HttpEntity)} */ @Deprecated public static String getContentMimeType(final HttpEntity entity) throws ParseException { Args.notNull(entity, "Entity"); String mimeType = null; if (entity.getContentType() != null) { final HeaderElement values[] = entity.getContentType().getElements(); if (values.length > 0) { mimeType = values[0].getName(); } } return mimeType; }
static MultipartFormEntityBytes buildMultipartFormEntityBytes(JSONObject params) throws ConnectionException { HttpEntity httpEntity = multiPartFormEntity(params); return new MultipartFormEntityBytes( httpEntity.getContentType().getName(), httpEntity.getContentType().getValue(), httpEntityToBytes(httpEntity)); }
/** * Obtains character set of the entity, if known. * * @param entity must not be null * @return the character set, or null if not found * @throws ParseException if header elements cannot be parsed * @throws IllegalArgumentException if entity is null * * @deprecated (4.1.3) use {@link ContentType#getOrDefault(HttpEntity)} */ @Deprecated public static String getContentCharSet(final HttpEntity entity) throws ParseException { Args.notNull(entity, "Entity"); String charset = null; if (entity.getContentType() != null) { final HeaderElement values[] = entity.getContentType().getElements(); if (values.length > 0) { final NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } return charset; }
/** * Extracts {@code Content-Type} value from {@link HttpEntity}. Returns {@code null} * if not specified or incorrect (could not be parsed).. * * @param entity HTTP entity * @return content type * * @since 4.4 * */ public static ContentType getLenient(final HttpEntity entity) { if (entity == null) { return null; } final Header header = entity.getContentType(); if (header != null) { try { final HeaderElement[] elements = header.getElements(); if (elements.length > 0) { return create(elements[0], false); } } catch (ParseException ex) { return null; } } return null; }
/** * Extracts {@code Content-Type} value from {@link HttpEntity} exactly as * specified by the {@code Content-Type} header of the entity. Returns {@code null} * if not specified. * * @param entity HTTP entity * @return content type * @throws ParseException if the given text does not represent a valid * {@code Content-Type} value. * @throws UnsupportedCharsetException Thrown when the named charset is not available in * this instance of the Java virtual machine */ public static ContentType get( final HttpEntity entity) throws ParseException, UnsupportedCharsetException { if (entity == null) { return null; } final Header header = entity.getContentType(); if (header != null) { final HeaderElement[] elements = header.getElements(); if (elements.length > 0) { return create(elements[0], true); } } return null; }
private void addContentTypeHeaderIfMissing(final HttpEntityEnclosingRequest request) { if (request.getEntity().getContentType() == null) { ((AbstractHttpEntity) request.getEntity()).setContentType( ContentType.APPLICATION_OCTET_STREAM.getMimeType()); } }
CloseableHttpResponse getReconstructedResponse() throws IOException { ensureConsumed(); final HttpResponse reconstructed = new BasicHttpResponse(response.getStatusLine()); reconstructed.setHeaders(response.getAllHeaders()); final CombinedEntity combinedEntity = new CombinedEntity(resource, instream); final HttpEntity entity = response.getEntity(); if (entity != null) { combinedEntity.setContentType(entity.getContentType()); combinedEntity.setContentEncoding(entity.getContentEncoding()); combinedEntity.setChunked(entity.isChunked()); } reconstructed.setEntity(combinedEntity); return (CloseableHttpResponse) Proxy.newProxyInstance( ResponseProxyHandler.class.getClassLoader(), new Class<?>[] { CloseableHttpResponse.class }, new ResponseProxyHandler(reconstructed) { @Override public void close() throws IOException { response.close(); } }); }
if (entity.getContentType() != null && !response.containsHeader( HTTP.CONTENT_TYPE )) { response.addHeader(entity.getContentType());
if (entity.getContentType() != null && !request.containsHeader( HTTP.CONTENT_TYPE )) { request.addHeader(entity.getContentType());