protected void captureContentEncoding(HttpResponse httpResponse) { contentEncoding = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_ENCODING); }
/** * Retrieves the Content-Type header of this message. If no Content-Type is present, returns the assumed default Content-Type (see * {@link BrowserMobHttpUtil#UNKNOWN_CONTENT_TYPE}). * * @return the message's content type */ public String getContentType() { String contentTypeHeader = HttpHeaders.getHeader(httpMessage, HttpHeaders.Names.CONTENT_TYPE); if (contentTypeHeader == null || contentTypeHeader.isEmpty()) { return BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE; } else { return contentTypeHeader; } }
/** * @deprecated Use {@link #getTimeMillis(CharSequence, long)} instead. * * Returns the date header value with the specified header name. If * there are more than one header value for the specified header name, the * first value is returned. * * @return the header value or the {@code defaultValue} if there is no such * header or the header value is not a formatted date */ @Deprecated public static Date getDateHeader(HttpMessage message, CharSequence name, Date defaultValue) { final String value = getHeader(message, name); Date date = DateFormatter.parseHttpDate(value); return date != null ? date : defaultValue; }
/** * Derives the charset from the Content-Type header in the HttpMessage. If the Content-Type header is not present or does not contain * a character set, this method returns the ISO-8859-1 character set. See {@link BrowserMobHttpUtil#readCharsetInContentTypeHeader(String)} * for more details. * * @param httpMessage HTTP message to extract charset from * @return the charset associated with the HTTP message, or the default charset if none is present * @throws UnsupportedCharsetException if there is a charset specified in the content-type header, but it is not supported */ public static Charset getCharsetFromMessage(HttpMessage httpMessage) throws UnsupportedCharsetException { String contentTypeHeader = HttpHeaders.getHeader(httpMessage, HttpHeaders.Names.CONTENT_TYPE); Charset charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentTypeHeader); if (charset == null) { return BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; } return charset; }
protected void captureRedirectUrl(HttpResponse httpResponse) { String locationHeaderValue = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.LOCATION); if (locationHeaderValue != null) { harEntry.getResponse().setRedirectURL(locationHeaderValue); } }
protected void captureResponseMimeType(HttpResponse httpResponse) { String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); // don't set the mimeType to null, since mimeType is a required field if (contentType != null) { harEntry.getResponse().getContent().setMimeType(contentType); } }
/** * Extracts the entity body from a FullHttpMessage, according to the character set in the message's Content-Type header. If the Content-Type * header is not present or does not specify a charset, assumes the ISO-8859-1 character set (see {@link BrowserMobHttpUtil#DEFAULT_HTTP_CHARSET}). * * @param httpMessage HTTP message to extract entity body from * @return String representation of the entity body * @throws java.nio.charset.UnsupportedCharsetException if there is a charset specified in the content-type header, but it is not supported */ public static String extractHttpEntityBody(FullHttpMessage httpMessage) { Charset charset; try { charset = getCharsetFromMessage(httpMessage); } catch (UnsupportedCharsetException e) { // the declared character set is not supported, so it is impossible to decode the contents of the message. log an error and throw an exception // to alert the client code. java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause(); String contentTypeHeader = HttpHeaders.getHeader(httpMessage, HttpHeaders.Names.CONTENT_TYPE); log.error("Cannot retrieve text contents of message because HTTP message declares a character set that is not supported on this platform. Content type header: {}.", contentTypeHeader, cause); throw cause; } return extractHttpEntityBody(httpMessage, charset); }
String contentType = HttpHeaders.getHeader(httpRequest, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in request to {}. Content will be treated as {}", httpRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE);
String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); if (contentType == null) { log.warn("No content type specified in response from {}. Content will be treated as {}", originalRequest.getUri(), BrowserMobHttpUtil.UNKNOWN_CONTENT_TYPE);
@Override public String getContentType() { return HttpHeaders.getHeader(this.originalRequest, HttpHeaders.Names.CONTENT_TYPE); }
@Override public String getContentType() { return HttpHeaders.getHeader(this.originalRequest, HttpHeaders.Names.CONTENT_TYPE); }
@Override public String getHeader(String name) { return HttpHeaders.getHeader(this.originalRequest, name); }
@Override public Locale getLocale() { String locale = HttpHeaders.getHeader(this.originalRequest, Names.ACCEPT_LANGUAGE, DEFAULT_LOCALE.toString()); return new Locale(locale); }
@Override public Locale getLocale() { String locale = HttpHeaders.getHeader(this.request, Names.ACCEPT_LANGUAGE, DEFAULT_LOCALE.toString()); return new Locale(locale); }
private Map<String, String> getHeaders(final HttpRequest request) { final Map<String, String> headers = new HashMap<String, String>(); for (String name : request.headers().names()) { // TODO: Add support for multi header headers.put(name, HttpHeaders.getHeader(request, name)); } return headers; }
private Map<String, String> getHeaders(final HttpRequest request) { final Map<String, String> headers = new HashMap<String, String>(); for (String name : request.headers().names()) { // TODO: Add support for multi header headers.put(name, HttpHeaders.getHeader(request, name)); } return headers; }
@Override public Enumeration getLocales() { Collection<Locale> locales = Utils .parseAcceptLanguageHeader(HttpHeaders .getHeader(this.originalRequest, HttpHeaders.Names.ACCEPT_LANGUAGE)); if (locales == null || locales.isEmpty()) { locales = new ArrayList<Locale>(); locales.add(Locale.getDefault()); } return Utils.enumeration(locales); }
protected void captureRedirectUrl(HttpResponse httpResponse) { String locationHeaderValue = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.LOCATION); if (locationHeaderValue != null) { harEntry.getResponse().setRedirectURL(locationHeaderValue); } }
protected void captureRedirectUrl(HttpResponse httpResponse) { Log.e("InnerHandle", "captureRedirectUrl " + harEntry.getId()); String locationHeaderValue = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.LOCATION); if (locationHeaderValue != null) { harResponse.getResponse().setRedirectURL(locationHeaderValue); } }
protected void captureResponseMimeType(HttpResponse httpResponse) { String contentType = HttpHeaders.getHeader(httpResponse, HttpHeaders.Names.CONTENT_TYPE); // don't set the mimeType to null, since mimeType is a required field if (contentType != null) { harEntry.getResponse().getContent().setMimeType(contentType); } }