public class BrowserMobProxyServer extends Object implements BrowserMobProxy
BrowserMobProxy
.Modifier and Type | Field and Description |
---|---|
static String |
VIA_HEADER_ALIAS
The default pseudonym to use when adding the Via header to proxied requests.
|
Constructor and Description |
---|
BrowserMobProxyServer() |
Modifier and Type | Method and Description |
---|---|
void |
abort()
Like
BrowserMobProxy.stop() , shuts down the proxy server and no longer accepts incoming connections, but does not wait for any existing
network traffic to cease. |
protected void |
addBrowserMobFilters()
Adds the basic browsermob-proxy filters, except for the relatively-expensive HAR capture filter.
|
void |
addFirstHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
Adds a new filter factory (request/response interceptor) to the beginning of the HttpFilters chain.
|
protected void |
addHarCaptureFilter()
Enables the HAR capture filter if it has not already been enabled.
|
void |
addHeader(String name,
String value)
Adds a new HTTP header to every request.
|
void |
addHeaders(Map<String,String> headers)
Adds the specified HTTP headers to every request.
|
void |
addHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory) |
void |
addLastHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
Adds a new filter factory (request/response interceptor) to the end of the HttpFilters chain.
|
void |
addRequestFilter(RequestFilter filter)
Note: The current implementation of this method forces a maximum request size of 2 MiB.
|
void |
addResponseFilter(ResponseFilter filter)
Note: The current implementation of this method forces a maximum response size of 2 MiB.
|
void |
addWhitelistPattern(String urlPattern)
Adds a URL-matching regular expression to an existing whitelist.
|
void |
autoAuthorization(String domain,
String username,
String password,
AuthType authType)
Enables automatic authorization for the specified domain and auth type.
|
void |
blacklistRequests(String pattern,
int responseCode)
Adds a URL-matching regular expression to the blacklist.
|
void |
blacklistRequests(String pattern,
int responseCode,
String method)
Adds a URL-matching regular expression to the blacklist.
|
void |
chainedProxyAuthorization(String username,
String password,
AuthType authType)
Enables chained proxy authorization using the Proxy-Authorization header described in RFC 7235, section 4.4 (https://tools.ietf.org/html/rfc7235#section-4.4).
|
void |
clearBlacklist()
Clears any existing blacklist.
|
void |
clearRewriteRules()
Clears all existing rewrite rules.
|
void |
disableHarCaptureTypes(CaptureType... captureTypes)
Disables the specified HAR capture types.
|
void |
disableHarCaptureTypes(Set<CaptureType> captureTypes)
Disables the specified HAR capture types.
|
void |
disableWhitelist()
Clears any existing whitelist and disables whitelisting.
|
void |
enableEmptyWhitelist(int statusCode)
Enables the whitelist, but with no matching URLs.
|
void |
enableHarCaptureTypes(CaptureType... captureTypes)
Enables the specified HAR capture types.
|
void |
enableHarCaptureTypes(Set<CaptureType> captureTypes)
Enables the specified HAR capture types.
|
Har |
endHar()
Stops capturing traffic in the HAR.
|
void |
endPage() |
Map<String,String> |
getAllHeaders()
Returns all headers previously added with
BrowserMobProxy.addHeader(String name, String value) . |
Collection<BlacklistEntry> |
getBlacklist()
Returns all blacklist entries currently in effect.
|
InetSocketAddress |
getChainedProxy()
Returns the address and port of the upstream proxy.
|
InetAddress |
getClientBindAddress()
Returns the address of the network interface on which the proxy is listening for client connections.
|
HarPage |
getCurrentHarPage() |
List<org.littleshoot.proxy.HttpFiltersSource> |
getFilterFactories() |
Har |
getHar()
Retrieves the current HAR.
|
EnumSet<CaptureType> |
getHarCaptureTypes() |
AdvancedHostResolver |
getHostNameResolver()
Returns the current host name resolver.
|
int |
getPort()
Returns the actual port on which the proxy is listening for client connections.
|
long |
getReadBandwidthLimit()
Returns the current bandwidth limit for reading, in bytes per second.
|
Map<String,String> |
getRewriteRules()
Returns all rewrite rules currently in effect.
|
InetAddress |
getServerBindAddress()
Returns the address address of the network interface the proxy will use to initiate upstream connections.
|
int |
getWhitelistStatusCode()
Returns the status code returned for all URLs that do not match the whitelist.
|
Collection<String> |
getWhitelistUrls()
Returns the URL-matching regular expressions currently in effect.
|
long |
getWriteBandwidthLimit()
Returns the current bandwidth limit for writing, in bytes per second.
|
boolean |
isMitmDisabled() |
boolean |
isStarted()
Returns true if the proxy is started and listening for connections, otherwise false.
|
boolean |
isStopped() |
boolean |
isWhitelistEnabled()
Returns true if the whitelist is enabled, otherwise false.
|
Har |
newHar()
Starts a new HAR file with the default page name (see
BrowserMobProxy.newPage() . |
Har |
newHar(String initialPageRef)
Starts a new HAR file with the specified initialPageRef as the page name and page title.
|
Har |
newHar(String initialPageRef,
String initialPageTitle)
Starts a new HAR file with the specified page name and page title.
|
Har |
newPage()
Starts a new HAR page using the default page naming convention.
|
Har |
newPage(String pageRef)
Starts a new HAR page using the specified pageRef as the page name and the page title.
|
Har |
newPage(String pageRef,
String pageTitle)
Starts a new HAR page using the specified pageRef as the page name and the pageTitle as the page title.
|
void |
removeAllHeaders()
Removes all headers previously added with
BrowserMobProxy.addHeader(String name, String value) . |
void |
removeHeader(String name)
Removes a header previously added with
BrowserMobProxy.addHeader(String name, String value) . |
void |
removeRewriteRule(String urlPattern)
Removes an existing rewrite rule whose urlPattern matches the specified pattern.
|
void |
rewriteUrl(String pattern,
String replace)
Adds a rewrite rule for the specified URL-matching regular expression.
|
void |
rewriteUrls(Map<String,String> rewriteRules)
Replaces existing rewrite rules with the specified patterns and replacement expressions.
|
void |
setBlacklist(Collection<BlacklistEntry> blacklist)
Replaces any existing blacklist with the specified blacklist.
|
void |
setChainedProxy(InetSocketAddress chainedProxyAddress)
Instructs this proxy to route traffic through an upstream proxy.
|
void |
setChainedProxyManager(org.littleshoot.proxy.ChainedProxyManager chainedProxyManager)
Allows access to the LittleProxy
ChainedProxyManager for fine-grained control of the chained proxies. |
void |
setConnectTimeout(int connectTimeout,
TimeUnit timeUnit)
Maximum amount of time to wait to establish a connection to a remote server.
|
void |
setHarCaptureTypes(CaptureType... captureTypes)
Sets the data types that will be captured in the HAR file for future requests.
|
void |
setHarCaptureTypes(Set<CaptureType> harCaptureSettings)
Sets the data types that will be captured in the HAR file for future requests.
|
void |
setHostNameResolver(AdvancedHostResolver resolver)
Sets the resolver that will be used to look up host names.
|
void |
setIdleConnectionTimeout(int idleConnectionTimeout,
TimeUnit timeUnit)
The LittleProxy implementation only allows idle connection timeouts to be specified in seconds.
|
void |
setLatency(long latency,
TimeUnit timeUnit)
The minimum amount of time that will elapse between the time the proxy begins receiving a response from the server and the time the
proxy begins sending the response to the client.
|
void |
setMitmDisabled(boolean mitmDisabled)
Completely disables MITM for this proxy server.
|
void |
setMitmManager(org.littleshoot.proxy.MitmManager mitmManager)
Sets the MITM manager, which is responsible for generating forged SSL certificates to present to clients.
|
void |
setReadBandwidthLimit(long bytesPerSecond)
Sets the maximum bandwidth to consume when reading server responses.
|
void |
setRequestTimeout(int requestTimeout,
TimeUnit timeUnit)
Maximum amount of time to wait for an HTTP response from the remote server after the request has been sent in its entirety.
|
void |
setThreadPoolConfiguration(org.littleshoot.proxy.impl.ThreadPoolConfiguration threadPoolConfiguration)
Configures the Netty thread pool used by the LittleProxy back-end.
|
void |
setTrustAllServers(boolean trustAllServers)
Disables verification of all upstream servers' SSL certificates.
|
void |
setTrustSource(TrustSource trustSource)
Sets the
TrustSource that contains trusted root certificate authorities that will be used to validate
upstream servers' certificates. |
void |
setUseEcc(boolean useEcc) |
void |
setWriteBandwidthLimit(long bytesPerSecond)
Sets the maximum bandwidth to consume when sending requests to servers.
|
void |
start()
Starts the proxy on port 0 (a JVM-selected open port).
|
void |
start(int port)
Starts the proxy on the specified port.
|
void |
start(int port,
InetAddress bindAddress)
Starts the proxy on the specified port.
|
void |
start(int port,
InetAddress clientBindAddress,
InetAddress serverBindAddress)
Starts the proxy on the specified port.
|
void |
stop()
Stops accepting new client connections and initiates a graceful shutdown of the proxy server, waiting up to 5 seconds for network
traffic to stop.
|
protected void |
stop(boolean graceful) |
void |
stopAutoAuthorization(String domain)
Stops automatic authorization for the specified domain.
|
boolean |
waitForQuiescence(long quietPeriod,
long timeout,
TimeUnit timeUnit)
Waits for existing network traffic to stop, and for the specified quietPeriod to elapse.
|
void |
whitelistRequests(Collection<String> urlPatterns,
int statusCode)
Whitelists URLs matching the specified regular expression patterns.
|
void |
whitelistRequests(String[] patterns,
int responseCode)
Whitelist the specified request patterns, returning the specified responseCode for non-whitelisted
requests.
|
public static final String VIA_HEADER_ALIAS
public void start(int port, InetAddress clientBindAddress, InetAddress serverBindAddress)
BrowserMobProxy
start
in interface BrowserMobProxy
port
- port to listen onclientBindAddress
- address of the network interface on which the proxy will listen for connectionsserverBindAddress
- address of the network interface on which the proxy will connect to upstream serverspublic boolean isStarted()
BrowserMobProxy
isStarted
in interface BrowserMobProxy
public void start(int port)
BrowserMobProxy
start
in interface BrowserMobProxy
port
- port to listen onpublic void start(int port, InetAddress bindAddress)
BrowserMobProxy
start
in interface BrowserMobProxy
port
- port to listen onbindAddress
- address of the network interface on which the proxy will listen for connections and also attempt to connect to upstream servers.public void start()
BrowserMobProxy
start
in interface BrowserMobProxy
public void stop()
BrowserMobProxy
stop
in interface BrowserMobProxy
public void abort()
BrowserMobProxy
BrowserMobProxy.stop()
, shuts down the proxy server and no longer accepts incoming connections, but does not wait for any existing
network traffic to cease. Any existing connections to clients or to servers may be force-killed immediately.
If the proxy was previously stopped or aborted, this method has no effect.abort
in interface BrowserMobProxy
protected void stop(boolean graceful)
public InetAddress getClientBindAddress()
BrowserMobProxy
getClientBindAddress
in interface BrowserMobProxy
public int getPort()
BrowserMobProxy
getPort
in interface BrowserMobProxy
public InetAddress getServerBindAddress()
BrowserMobProxy
getServerBindAddress
in interface BrowserMobProxy
public Har getHar()
BrowserMobProxy
getHar
in interface BrowserMobProxy
public Har newHar()
BrowserMobProxy
BrowserMobProxy.newPage()
. Enables HAR capture if it was not previously enabled.newHar
in interface BrowserMobProxy
public Har newHar(String initialPageRef)
BrowserMobProxy
newHar
in interface BrowserMobProxy
initialPageRef
- initial page name of the new HAR filepublic Har newHar(String initialPageRef, String initialPageTitle)
BrowserMobProxy
newHar
in interface BrowserMobProxy
initialPageRef
- initial page name of the new HAR fileinitialPageTitle
- initial page title of the new HAR filepublic void setHarCaptureTypes(Set<CaptureType> harCaptureSettings)
BrowserMobProxy
CaptureType
data types. CaptureType
provides several
convenience methods to retrieve commonly-used capture settings.
Note: HAR capture must still be explicitly enabled via BrowserMobProxy.newHar()
or BrowserMobProxy.newHar(String)
to begin capturing
any request and response contents.setHarCaptureTypes
in interface BrowserMobProxy
harCaptureSettings
- HAR data types to capturepublic void setHarCaptureTypes(CaptureType... captureTypes)
BrowserMobProxy
CaptureType
data types. CaptureType
provides several
convenience methods to retrieve commonly-used capture settings.
Note: HAR capture must still be explicitly enabled via BrowserMobProxy.newHar()
or BrowserMobProxy.newHar(String)
to begin capturing
any request and response contents.setHarCaptureTypes
in interface BrowserMobProxy
captureTypes
- HAR data types to capturepublic EnumSet<CaptureType> getHarCaptureTypes()
getHarCaptureTypes
in interface BrowserMobProxy
public void enableHarCaptureTypes(Set<CaptureType> captureTypes)
BrowserMobProxy
enableHarCaptureTypes
in interface BrowserMobProxy
captureTypes
- capture types to enablepublic void enableHarCaptureTypes(CaptureType... captureTypes)
BrowserMobProxy
enableHarCaptureTypes
in interface BrowserMobProxy
captureTypes
- capture types to enablepublic void disableHarCaptureTypes(Set<CaptureType> captureTypes)
BrowserMobProxy
disableHarCaptureTypes
in interface BrowserMobProxy
captureTypes
- capture types to disablepublic void disableHarCaptureTypes(CaptureType... captureTypes)
BrowserMobProxy
disableHarCaptureTypes
in interface BrowserMobProxy
captureTypes
- capture types to disablepublic Har newPage()
BrowserMobProxy
BrowserMobProxy.newHar()
or BrowserMobProxy.newHar(String)
is called, and increments on every subsequent call to BrowserMobProxy.newPage()
or
BrowserMobProxy.newHar(String)
. Populates the HarPageTimings.onLoad
value based on the amount of time
the current page has been captured.newPage
in interface BrowserMobProxy
public Har newPage(String pageRef)
BrowserMobProxy
HarPageTimings.onLoad
value based on the amount of time the current page has been captured.newPage
in interface BrowserMobProxy
pageRef
- name of the new pagepublic Har newPage(String pageRef, String pageTitle)
BrowserMobProxy
HarPageTimings.onLoad
value based on the amount of time the current page has been captured.newPage
in interface BrowserMobProxy
pageRef
- name of the new pagepageTitle
- title of the new pagepublic Har endHar()
BrowserMobProxy
HarPageTimings.onLoad
value for the current page
based on the amount of time it has been captured.endHar
in interface BrowserMobProxy
public void setReadBandwidthLimit(long bytesPerSecond)
BrowserMobProxy
setReadBandwidthLimit
in interface BrowserMobProxy
bytesPerSecond
- maximum bandwidth, in bytes per secondpublic long getReadBandwidthLimit()
BrowserMobProxy
getReadBandwidthLimit
in interface BrowserMobProxy
public void setWriteBandwidthLimit(long bytesPerSecond)
BrowserMobProxy
setWriteBandwidthLimit
in interface BrowserMobProxy
bytesPerSecond
- maximum bandwidth, in bytes per secondpublic long getWriteBandwidthLimit()
BrowserMobProxy
getWriteBandwidthLimit
in interface BrowserMobProxy
public void endPage()
public void addHeaders(Map<String,String> headers)
BrowserMobProxy
addHeaders
in interface BrowserMobProxy
headers
- Map<header name, header value>
to append to every request.public void setLatency(long latency, TimeUnit timeUnit)
BrowserMobProxy
setLatency
in interface BrowserMobProxy
latency
- minimum latency, or 0 for no minimumtimeUnit
- TimeUnit for the latencypublic void autoAuthorization(String domain, String username, String password, AuthType authType)
BrowserMobProxy
autoAuthorization
in interface BrowserMobProxy
domain
- domain automatically send authorization information tousername
- authorization usernamepassword
- authorization passwordauthType
- authorization typepublic void stopAutoAuthorization(String domain)
BrowserMobProxy
stopAutoAuthorization
in interface BrowserMobProxy
domain
- domain to stop automatically sending authorization information topublic void chainedProxyAuthorization(String username, String password, AuthType authType)
BrowserMobProxy
AuthType.BASIC
authentication is supported.chainedProxyAuthorization
in interface BrowserMobProxy
username
- the username to use to authenticate with the chained proxypassword
- the password to use to authenticate with the chained proxyauthType
- the auth type to use (currently, must be BASIC)public void setConnectTimeout(int connectTimeout, TimeUnit timeUnit)
BrowserMobProxy
setConnectTimeout
in interface BrowserMobProxy
connectTimeout
- maximum time to wait to establish a connection to a server, or 0 to wait indefinitelytimeUnit
- TimeUnit for the connectionTimeoutpublic void setIdleConnectionTimeout(int idleConnectionTimeout, TimeUnit timeUnit)
setIdleConnectionTimeout
in interface BrowserMobProxy
idleConnectionTimeout
- maximum time to allow a connection to remain idle, or 0 to wait indefinitely.timeUnit
- TimeUnit for the idleConnectionTimeoutpublic void setRequestTimeout(int requestTimeout, TimeUnit timeUnit)
BrowserMobProxy
setRequestTimeout
in interface BrowserMobProxy
requestTimeout
- maximum time to wait for an HTTP response, or 0 to wait indefinitelytimeUnit
- TimeUnit for the requestTimeoutpublic void rewriteUrl(String pattern, String replace)
BrowserMobProxy
Pattern
).
The replacementExpression may consist of capture groups specified in the urlPattern, denoted
by a $ (see Matcher.appendReplacement(StringBuffer, String)
.
For HTTP requests (not HTTPS), if the hostname and/or port is changed as a result of a rewrite rule, the Host header of the request will be modified
to reflect the updated hostname/port. For HTTPS requests, the host and port cannot be changed by rewrite rules
(use BrowserMobProxy.getHostNameResolver()
and AdvancedHostResolver.remapHost(String, String)
to direct HTTPS requests
to a different host).
Note: The rewriting applies to the entire URL, including scheme (http:// or https://), hostname/address, port, and query string. Note that this means
a urlPattern of "http://www\.website\.com/page"
will NOT match http://www.website.com:80/page
.
For example, the following rewrite rule:
proxy.rewriteUrl("http://www\\.(yahoo|bing)\\.com/\\?(\\w+)=(\\w+)", "http://www.google.com/?originalDomain=$1&$2=$3");
will match an HTTP request (but not HTTPS!) to www.yahoo.com or www.bing.com with exactly 1 query parameter,
and replace it with a call to www.google.com with an 'originalDomain' query parameter, as well as the original query parameter.
When applied to the URL:
http://www.yahoo.com?theFirstParam=someValue
will result in the proxy making a request to:
http://www.google.com?originalDomain=yahoo&theFirstParam=someValue
When applied to the URL:
http://www.bing.com?anotherParam=anotherValue
will result in the proxy making a request to:
http://www.google.com?originalDomain=bing&anotherParam=anotherValue
rewriteUrl
in interface BrowserMobProxy
pattern
- URL-matching regular expressionreplace
- an expression, which may optionally contain capture groups, which will replace any URL which matches urlPatternpublic void rewriteUrls(Map<String,String> rewriteRules)
BrowserMobProxy
BrowserMobProxy.rewriteUrl(String, String)
for details on the format of the rewrite rules.rewriteUrls
in interface BrowserMobProxy
rewriteRules
- Map<urlPattern, replacementExpression>
public void clearRewriteRules()
BrowserMobProxy
clearRewriteRules
in interface BrowserMobProxy
public void blacklistRequests(String pattern, int responseCode)
BrowserMobProxy
blacklistRequests
in interface BrowserMobProxy
pattern
- URL-matching regular expression to blacklistresponseCode
- HTTP status code to returnpublic void blacklistRequests(String pattern, int responseCode, String method)
BrowserMobProxy
BrowserMobProxy.blacklistRequests(String, int)
for details on the URL the urlPattern will match.blacklistRequests
in interface BrowserMobProxy
pattern
- URL-matching regular expression to blacklistresponseCode
- HTTP status code to returnmethod
- regular expression matching a request's HTTP methodpublic void setBlacklist(Collection<BlacklistEntry> blacklist)
BrowserMobProxy
setBlacklist
in interface BrowserMobProxy
blacklist
- new blacklist entriespublic Collection<BlacklistEntry> getBlacklist()
BrowserMobProxy
getBlacklist
in interface BrowserMobProxy
public boolean isWhitelistEnabled()
BrowserMobProxy
isWhitelistEnabled
in interface BrowserMobProxy
public Collection<String> getWhitelistUrls()
BrowserMobProxy
getWhitelistUrls
in interface BrowserMobProxy
public int getWhitelistStatusCode()
BrowserMobProxy
getWhitelistStatusCode
in interface BrowserMobProxy
public void clearBlacklist()
BrowserMobProxy
clearBlacklist
in interface BrowserMobProxy
public void whitelistRequests(Collection<String> urlPatterns, int statusCode)
BrowserMobProxy
whitelistRequests
in interface BrowserMobProxy
urlPatterns
- URL-matching regular expressions to whitelist; null or an empty collection will enable an empty whiteliststatusCode
- HTTP status code to return to clients when a URL matches a patternpublic void addWhitelistPattern(String urlPattern)
BrowserMobProxy
addWhitelistPattern
in interface BrowserMobProxy
urlPattern
- URL-matching regular expressions to whitelistpublic void whitelistRequests(String[] patterns, int responseCode)
patterns
- regular expression strings matching URL patterns to whitelist. if empty or null,
the whitelist will be enabled but will not match any URLs.responseCode
- the HTTP response code to return for non-whitelisted requestspublic void enableEmptyWhitelist(int statusCode)
BrowserMobProxy
enableEmptyWhitelist
in interface BrowserMobProxy
statusCode
- HTTP status code to return to clients on all requestspublic void disableWhitelist()
BrowserMobProxy
disableWhitelist
in interface BrowserMobProxy
public void addHeader(String name, String value)
BrowserMobProxy
addHeader
in interface BrowserMobProxy
name
- name of the header to addvalue
- new header's valuepublic void removeHeader(String name)
BrowserMobProxy
BrowserMobProxy.addHeader(String name, String value)
.removeHeader
in interface BrowserMobProxy
name
- previously-added header's namepublic void removeAllHeaders()
BrowserMobProxy
BrowserMobProxy.addHeader(String name, String value)
.removeAllHeaders
in interface BrowserMobProxy
public Map<String,String> getAllHeaders()
BrowserMobProxy
BrowserMobProxy.addHeader(String name, String value)
.getAllHeaders
in interface BrowserMobProxy
Map<header name, header value>
public void setHostNameResolver(AdvancedHostResolver resolver)
BrowserMobProxy
ChainedHostResolver
.setHostNameResolver
in interface BrowserMobProxy
resolver
- host name resolverpublic AdvancedHostResolver getHostNameResolver()
BrowserMobProxy
getHostNameResolver
in interface BrowserMobProxy
public boolean waitForQuiescence(long quietPeriod, long timeout, TimeUnit timeUnit)
BrowserMobProxy
waitForQuiescence
in interface BrowserMobProxy
quietPeriod
- amount of time after which network traffic will be considered "stopped"timeout
- maximum amount of time to wait for network traffic to stoptimeUnit
- TimeUnit for the quietPeriod and timeoutpublic void setChainedProxy(InetSocketAddress chainedProxyAddress)
Note: Using setChainedProxyManager(ChainedProxyManager)
will supersede any value set by this method.
setChainedProxy
in interface BrowserMobProxy
chainedProxyAddress
- address of the upstream proxypublic InetSocketAddress getChainedProxy()
BrowserMobProxy
getChainedProxy
in interface BrowserMobProxy
public void setChainedProxyManager(org.littleshoot.proxy.ChainedProxyManager chainedProxyManager)
ChainedProxyManager
for fine-grained control of the chained proxies. To enable a single
chained proxy, BrowserMobProxy.setChainedProxy(InetSocketAddress)
is generally more convenient.chainedProxyManager
- chained proxy manager to enablepublic void setThreadPoolConfiguration(org.littleshoot.proxy.impl.ThreadPoolConfiguration threadPoolConfiguration)
ThreadPoolConfiguration
for details.threadPoolConfiguration
- thread pool configuration to usepublic void addFirstHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
BrowserMobProxy
HttpFiltersSource.filterRequest(io.netty.handler.codec.http.HttpRequest, io.netty.channel.ChannelHandlerContext)
method and returning an
HttpFilters
instance (typically, a subclass of HttpFiltersAdapter
).
To disable or bypass a filter on a per-request basis, the filterRequest() method may return null.addFirstHttpFilterFactory
in interface BrowserMobProxy
filterFactory
- factory to generate HttpFilterspublic void addLastHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
BrowserMobProxy
HttpFiltersSource.filterRequest(io.netty.handler.codec.http.HttpRequest, io.netty.channel.ChannelHandlerContext)
method and returning an
HttpFilters
instance (typically, a subclass of HttpFiltersAdapter
).
To disable or bypass a filter on a per-request basis, the filterRequest() method may return null.addLastHttpFilterFactory
in interface BrowserMobProxy
filterFactory
- factory to generate HttpFilterspublic void addResponseFilter(ResponseFilter filter)
HttpMessageContents
), you may add the filter source
directly: addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter, bufferSizeInBytes));
addResponseFilter
in interface BrowserMobProxy
filter
- filter instancepublic void addRequestFilter(RequestFilter filter)
HttpMessageContents
), you may add the filter source
directly: addFirstHttpFilterFactory(new RequestFilterAdapter.FilterSource(filter, bufferSizeInBytes));
addRequestFilter
in interface BrowserMobProxy
filter
- filter instancepublic Map<String,String> getRewriteRules()
BrowserMobProxy
getRewriteRules
in interface BrowserMobProxy
Map<URL-matching regex, replacement expression>
public void removeRewriteRule(String urlPattern)
BrowserMobProxy
removeRewriteRule
in interface BrowserMobProxy
urlPattern
- rewrite rule pattern to removepublic boolean isStopped()
public HarPage getCurrentHarPage()
public void addHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
public List<org.littleshoot.proxy.HttpFiltersSource> getFilterFactories()
public void setMitmDisabled(boolean mitmDisabled) throws IllegalStateException
BrowserMobProxy
setMitmDisabled
in interface BrowserMobProxy
mitmDisabled
- when true, MITM capture will be disabledIllegalStateException
- if the proxy is already startedpublic void setMitmManager(org.littleshoot.proxy.MitmManager mitmManager)
BrowserMobProxy
ImpersonatingMitmManager
and ImpersonatingMitmManager.Builder
for details on customizing the root and server certificate generation.setMitmManager
in interface BrowserMobProxy
mitmManager
- MITM manager to usepublic void setTrustAllServers(boolean trustAllServers)
BrowserMobProxy
setTrustAllServers
in interface BrowserMobProxy
trustAllServers
- when true, disables upstream server certificate verificationpublic void setTrustSource(TrustSource trustSource)
BrowserMobProxy
TrustSource
that contains trusted root certificate authorities that will be used to validate
upstream servers' certificates. When null, disables certificate validation (see warning at BrowserMobProxy.setTrustAllServers(boolean)
).setTrustSource
in interface BrowserMobProxy
trustSource
- TrustSource containing root CAs, or null to disable upstream server validationpublic boolean isMitmDisabled()
public void setUseEcc(boolean useEcc)
protected void addBrowserMobFilters()
protected void addHarCaptureFilter()
Copyright © 2016. All Rights Reserved.