public class BrowserMobHttpUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DECOMPRESS_BUFFER_SIZE
Buffer size when decompressing content.
|
static Charset |
DEFAULT_HTTP_CHARSET
The default charset when the Content-Type header does not specify a charset.
|
static String |
UNKNOWN_CONTENT_TYPE
Default MIME content type if no Content-Type header is present.
|
| Constructor and Description |
|---|
BrowserMobHttpUtil() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
decompressContents(byte[] fullMessage)
Decompresses the gzipped byte stream.
|
static byte[] |
extractReadableBytes(io.netty.buffer.ByteBuf content)
Extracts all readable bytes from the ByteBuf as a byte array.
|
static String |
getContentAsString(byte[] content,
Charset charset)
Converts the byte array into a String based on the specified charset.
|
static long |
getHeaderSize(io.netty.handler.codec.http.HttpHeaders headers)
Returns the size of the headers, including the 2 CRLFs at the end of the header block.
|
static String |
getHostAndPortFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
Gets the host and port from the specified request.
|
static String |
getHostAndPortFromUri(String uriString)
Retrieves the host and port from the specified URI.
|
static String |
getHostFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
Identify the host of an HTTP request.
|
static String |
getPathFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
Retrieves the path + query string from the specified request.
|
static String |
getPathFromUri(String uriString)
Retrieves the path from the URI, stripping out the scheme, host, and port.
|
static boolean |
hasTextualContent(String contentType)
Returns true if the content type string indicates textual content.
|
static boolean |
isRedirect(io.netty.handler.codec.http.HttpResponse httpResponse)
Returns true if the specified response is an HTTP redirect response, i.e.
|
static Charset |
readCharsetInContentTypeHeader(String contentTypeHeader)
Reads the charset directly from the Content-Type header string.
|
static boolean |
startsWithHttpOrHttps(String uri)
Returns true if the string starts with http:// or https://.
|
public static final String UNKNOWN_CONTENT_TYPE
Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media
type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY
attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to
identify the resource. If the media type remains unknown, the recipient SHOULD treat it as
type "application/octet-stream".
public static final Charset DEFAULT_HTTP_CHARSET
When no explicit charset parameter is provided by the sender, media subtypes of the "text" type are defined to have a default
charset value of "ISO-8859-1" when received via HTTP. Data in character sets other than "ISO-8859-1" or its subsets MUST be
labeled with an appropriate charset value.
public static final int DECOMPRESS_BUFFER_SIZE
public static long getHeaderSize(io.netty.handler.codec.http.HttpHeaders headers)
headers - headers to sizepublic static byte[] decompressContents(byte[] fullMessage)
throws DecompressionException
fullMessage - gzipped byte stream to decomressDecompressionException - thrown if the fullMessage cannot be read or decompressed for any reasonpublic static boolean hasTextualContent(String contentType)
text/
application/x-javascript
application/javascript
application/json
application/xml
application/xhtml+xml
contentType - contentType string to parsepublic static byte[] extractReadableBytes(io.netty.buffer.ByteBuf content)
content - ByteBuf to readpublic static String getContentAsString(byte[] content, Charset charset)
content - bytes to convert to a Stringcharset - the character set of the contentIllegalArgumentException - if charset is nullpublic static Charset readCharsetInContentTypeHeader(String contentTypeHeader) throws UnsupportedCharsetException
contentTypeHeader - the Content-Type header string; can be null or emptyUnsupportedCharsetException - if there is a charset specified in the content-type header, but it is not supported on this platformpublic static String getHostFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
httpRequest - HTTP request to parse the host frompublic static String getHostAndPortFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
httpRequest - HTTP requestpublic static String getPathFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
httpRequest - HTTP requestpublic static boolean startsWithHttpOrHttps(String uri)
uri - string to evaluatepublic static String getPathFromUri(String uriString) throws URISyntaxException
uriString - the URI to parse, containing a scheme, host, port, and pathURISyntaxException - if the specified URI is invalid or cannot be parsedpublic static String getHostAndPortFromUri(String uriString) throws URISyntaxException
uriString - URI to retrieve the host and port fromURISyntaxException - if the specified URI is invalid or cannot be parsedpublic static boolean isRedirect(io.netty.handler.codec.http.HttpResponse httpResponse)
httpResponse - HTTP responseCopyright © 2015. All Rights Reserved.