/** * Returns true if this message's Content-Type header indicates that it contains a textual data type. See {@link BrowserMobHttpUtil#hasTextualContent(String)}. * * @return true if the Content-Type header is a textual type, otherwise false */ public boolean isText() { return BrowserMobHttpUtil.hasTextualContent(getContentType()); } }
/** * Retrieves the character set of the entity body. If the Content-Type is not a textual type, this value is meaningless. * If no character set is specified, this method will return the default ISO-8859-1 character set. If the Content-Type * specifies a character set, but the character set is not supported on this platform, this method throws an * {@link java.nio.charset.UnsupportedCharsetException}. * * @return the entity body's character set * @throws java.nio.charset.UnsupportedCharsetException if the character set declared in the message is not supported on this platform */ public Charset getCharset() throws java.nio.charset.UnsupportedCharsetException { String contentTypeHeader = getContentType(); Charset charset = null; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentTypeHeader); } catch (UnsupportedCharsetException e) { java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause(); log.error("Character set specified in Content-Type header is not supported on this platform. Content-Type header: {}", contentTypeHeader, cause); throw cause; } if (charset == null) { return BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; } return charset; }
@Override public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) { if (!active) return; responses.add(new Response(messageInfo.getUrl(), response.getStatus().code(), response.getStatus().reasonPhrase(), toMap(response.headers()), contents.getContentType(), contents.getTextContents() )); if (response.getStatus().code() < 200 || response.getStatus().code() >= 300) return; String fileName = getFileName(response); if (fileName == null) return; File file = downloader.prepareTargetFile(config, fileName); try { FileUtils.writeByteArrayToFile(file, contents.getBinaryContents()); downloadedFiles.add(file); } catch (IOException e) { log.log(Level.SEVERE, "Failed to save downloaded file to " + file.getAbsolutePath() + " for url " + messageInfo.getUrl(), e); } }
/** * Returns true if this message's Content-Type header indicates that it contains a textual data type. See {@link BrowserMobHttpUtil#hasTextualContent(String)}. * * @return true if the Content-Type header is a textual type, otherwise false */ public boolean isText() { return BrowserMobHttpUtil.hasTextualContent(getContentType()); } }
/** * Returns true if this message's Content-Type header indicates that it contains a textual data type. See {@link BrowserMobHttpUtil#hasTextualContent(String)}. * * @return true if the Content-Type header is a textual type, otherwise false */ public boolean isText() { return BrowserMobHttpUtil.hasTextualContent(getContentType()); } }
/** * Retrieves the character set of the entity body. If the Content-Type is not a textual type, this value is meaningless. * If no character set is specified, this method will return the default ISO-8859-1 character set. If the Content-Type * specifies a character set, but the character set is not supported on this platform, this method throws an * {@link java.nio.charset.UnsupportedCharsetException}. * * @return the entity body's character set * @throws java.nio.charset.UnsupportedCharsetException if the character set declared in the message is not supported on this platform */ public Charset getCharset() throws java.nio.charset.UnsupportedCharsetException { String contentTypeHeader = getContentType(); Charset charset = null; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentTypeHeader); } catch (UnsupportedCharsetException e) { java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause(); log.error("Character set specified in Content-Type header is not supported on this platform. Content-Type header: {}", contentTypeHeader, cause); throw cause; } if (charset == null) { return BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; } return charset; }
/** * Retrieves the character set of the entity body. If the Content-Type is not a textual type, this value is meaningless. * If no character set is specified, this method will return the default ISO-8859-1 character set. If the Content-Type * specifies a character set, but the character set is not supported on this platform, this method throws an * {@link java.nio.charset.UnsupportedCharsetException}. * * @return the entity body's character set * @throws java.nio.charset.UnsupportedCharsetException if the character set declared in the message is not supported on this platform */ public Charset getCharset() throws java.nio.charset.UnsupportedCharsetException { String contentTypeHeader = getContentType(); Charset charset = null; try { charset = BrowserMobHttpUtil.readCharsetInContentTypeHeader(contentTypeHeader); } catch (UnsupportedCharsetException e) { java.nio.charset.UnsupportedCharsetException cause = e.getUnsupportedCharsetExceptionCause(); log.error("Character set specified in Content-Type header is not supported on this platform. Content-Type header: {}", contentTypeHeader, cause); throw cause; } if (charset == null) { return BrowserMobHttpUtil.DEFAULT_HTTP_CHARSET; } return charset; }