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 |
getRawPathAndParamsFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest)
Retrieves the raw (unescaped) path + query string from the specified request.
|
static String |
getRawPathAndParamsFromUri(String uriString)
Retrieves the raw (unescaped) path and query parameters 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 String |
removeMatchingPort(String hostWithPort,
int portNumber)
Removes a port from a host+port if the string contains the specified port.
|
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 getRawPathAndParamsFromRequest(io.netty.handler.codec.http.HttpRequest httpRequest) throws URISyntaxException
httpRequest
- HTTP requestURISyntaxException
- if the path could not be parsed (due to invalid characters in the URI, etc.)public static String getRawPathAndParamsFromUri(String uriString) throws URISyntaxException
uriString
- the URI to parse, containing a scheme, host, port, path, and query parametersURISyntaxException
- if the specified URI is invalid or cannot be parsedpublic static boolean isRedirect(io.netty.handler.codec.http.HttpResponse httpResponse)
httpResponse
- HTTP responsepublic static String removeMatchingPort(String hostWithPort, int portNumber)
www.website.com:443
, this method will return www.website.com
.
Note: The hostWithPort string is not a URI and should not contain a scheme or resource. This method does
not attempt to validate the specified host; it might throw IllegalArgumentException if there was a problem
parsing the hostname, but makes no guarantees. In general, it should be validated externally, if necessary.hostWithPort
- string containing a hostname and optional portportNumber
- port to remove from the stringCopyright © 2016. All Rights Reserved.