public ApacheFromServer(final URI originalUri, final HttpResponse response) { this.uri = originalUri; this.response = response; this.entity = response.getEntity(); if (entity != null) { try { this.inputStream = entity.getContent(); } catch (IOException e) { throw new RuntimeException("Could not get input stream from apache http client", e); } } else { this.inputStream = null; } this.headers = new ArrayList<>(response.getAllHeaders().length); for (org.apache.http.Header header : response.getAllHeaders()) { headers.add(Header.keyValue(header.getName(), header.getValue())); } addCookieStore(uri, headers); }
protected static String value(final String raw) { return cleanQuotes(raw.substring(raw.indexOf(':') + 1).trim()); }
private BufferedInputStream handleEncoding(final BufferedInputStream is) throws IOException { Header<?> encodingHeader = Header.find(headers, "Content-Encoding"); if (encodingHeader != null) { if (encodingHeader.getValue().equals("gzip")) { return new BufferedInputStream(new GZIPInputStream(is)); } else if (encodingHeader.getValue().equals("deflate")) { return new BufferedInputStream(new InflaterInputStream(is)); } } return is; }
public ApacheFromServer(final URI originalUri, final HttpResponse response) { this.uri = originalUri; this.response = response; this.entity = response.getEntity(); if (entity != null) { try { this.inputStream = entity.getContent(); } catch (IOException e) { throw new RuntimeException("Could not get input stream from apache http client", e); } } else { this.inputStream = null; } this.headers = new ArrayList<>(response.getAllHeaders().length); for (org.apache.http.Header header : response.getAllHeaders()) { headers.add(Header.keyValue(header.getName(), header.getValue())); } addCookieStore(uri, headers); }
/** * Creates a `Header` from a full header string. The string format is colon-delimited as `KEY:VALUE`. * * [source,groovy] * ---- * Header header = Header.full('Content-Type:text/plain') * assert header.key == 'Content-Type' * assert header.value == 'text/plain' * ---- * * @param raw the full header string * @return the `Header` representing the given header string */ public static Header<?> full(final String raw) { return keyValue(key(raw), value(raw)); }
/** * Creates a `Header` from a full header string. The string format is colon-delimited as `KEY:VALUE`. * * [source,groovy] * ---- * Header header = Header.full('Content-Type:text/plain') * assert header.key == 'Content-Type' * assert header.value == 'text/plain' * ---- * * @param raw the full header string * @return the `Header` representing the given header string */ public static Header<?> full(final String raw) { return keyValue(key(raw), value(raw)); }
/** * Creates a `Header` from a full header string. The string format is colon-delimited as `KEY:VALUE`. * * [source,groovy] * ---- * Header header = Header.full('Content-Type:text/plain') * assert header.key == 'Content-Type' * assert header.value == 'text/plain' * ---- * * @param raw the full header string * @return the `Header` representing the given header string */ public static Header<?> full(final String raw) { return keyValue(key(raw), value(raw)); }
/** * Retrieves the value of the charset from the "Content-Type" response header. * * @return the value of the charset from the "Content-Type" response header */ default Charset getCharset() { final Header.CombinedMap header = (Header.CombinedMap) Header.find(getHeaders(), "Content-Type"); if (header == null) { return StandardCharsets.UTF_8; } if (header.getParsed().containsKey("charset")) { Charset.forName(header.getParsed().get("charset")); } return StandardCharsets.UTF_8; }
/** * Retrieves the value of the charset from the "Content-Type" response header. * * @return the value of the charset from the "Content-Type" response header */ default Charset getCharset() { final Header.CombinedMap header = (Header.CombinedMap) Header.find(getHeaders(), "Content-Type"); if (header == null) { return StandardCharsets.UTF_8; } if (header.getParsed().containsKey("charset")) { Charset.forName(header.getParsed().get("charset")); } return StandardCharsets.UTF_8; }
private List<Header<?>> populateHeaders() { final List<Header<?>> ret = new ArrayList<>(); for (int i = 0; i < Integer.MAX_VALUE; ++i) { final String key = clean(connection.getHeaderFieldKey(i)); final String value = clean(connection.getHeaderField(i)); if (key == null && value == null) { break; } if (key != null && value != null) { ret.add(Header.keyValue(key.trim(), value.trim())); } } return Collections.unmodifiableList(ret); }
protected static String value(final String raw) { return cleanQuotes(raw.substring(raw.indexOf(':') + 1).trim()); }
/** * Retrieves the value of the charset from the "Content-Type" response header. * * @return the value of the charset from the "Content-Type" response header */ default Charset getCharset() { final Header.CombinedMap header = (Header.CombinedMap) Header.find(getHeaders(), "Content-Type"); if (header == null) { return StandardCharsets.UTF_8; } if (header.getParsed().containsKey("charset")) { Charset.forName(header.getParsed().get("charset")); } return StandardCharsets.UTF_8; }
protected static String value(final String raw) { return cleanQuotes(raw.substring(raw.indexOf(':') + 1).trim()); }
/** * Retrieves the value of the "Content-Type" header from the response. * * @return the value of the "Content-Type" response header */ default String getContentType() { final Header.CombinedMap header = (Header.CombinedMap) Header.find(getHeaders(), "Content-Type"); if (header == null) { return DEFAULT_CONTENT_TYPE; } else { return header.getParsed().get("Content-Type"); } }
/** * Retrieves the value of the "Content-Type" header from the response. * * @return the value of the "Content-Type" response header */ default String getContentType() { final Header.CombinedMap header = (Header.CombinedMap) Header.find(getHeaders(), "Content-Type"); if (header == null) { return DEFAULT_CONTENT_TYPE; } else { return header.getParsed().get("Content-Type"); } }
/** * Retrieves the parsed representation of the 'value`. The type of * the returned `Object` depends on the header and will be given * by the `getParsedType()` property. * * @return the parsed header value */ public T getParsed() { if (parsed == null) { this.parsed = parse(); } return parsed; }
/** * Retrieves the value of the "Content-Type" header from the response. * * @return the value of the "Content-Type" response header */ default String getContentType() { final Header.CombinedMap header = (Header.CombinedMap) Header.find(getHeaders(), "Content-Type"); if (header == null) { return DEFAULT_CONTENT_TYPE; } else { return header.getParsed().get("Content-Type"); } }
/** * Retrieves the parsed representation of the 'value`. The type of * the returned `Object` depends on the header and will be given * by the `getParsedType()` property. * * @return the parsed header value */ public T getParsed() { if (parsed == null) { this.parsed = parse(); } return parsed; }