Package com.browserup.bup
Class BrowserUpProxyServer
- java.lang.Object
-
- com.browserup.bup.BrowserUpProxyServer
-
- All Implemented Interfaces:
BrowserUpProxy
public class BrowserUpProxyServer extends java.lang.Object implements BrowserUpProxy
A LittleProxy-based implementation ofBrowserUpProxy.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_PAGE_REFstatic java.lang.StringDEFAULT_PAGE_TITLEstatic java.lang.StringVIA_HEADER_ALIASThe default pseudonym to use when adding the Via header to proxied requests.
-
Constructor Summary
Constructors Constructor Description BrowserUpProxyServer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()LikeBrowserUpProxy.stop(), shuts down the proxy server and no longer accepts incoming connections, but does not wait for any existing network traffic to cease.protected voidaddBrowserUpFilters()Adds the basic BrowserUp-proxy filters, except for the relatively-expensive HAR capture filter.voidaddFirstHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)Adds a new filter factory (request/response interceptor) to the beginning of the HttpFilters chain.protected voidaddHarCaptureFilter()Enables the HAR capture filter if it has not already been enabled.voidaddHeader(java.lang.String name, java.lang.String value)Adds a new HTTP header to every request.voidaddHeaders(java.util.Map<java.lang.String,java.lang.String> headers)Adds the specified HTTP headers to every request.voidaddHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)voidaddLastHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)Adds a new filter factory (request/response interceptor) to the end of the HttpFilters chain.voidaddRequestFilter(RequestFilter filter)Note: The current implementation of this method forces a maximum request size of 2 MiB.voidaddResponseFilter(ResponseFilter filter)Note: The current implementation of this method forces a maximum response size of 2 MiB.voidaddWhitelistPattern(java.lang.String urlPattern)Adds a URL-matching regular expression to an existing whitelist.AssertionResultassertAnyUrlContentContains(java.util.regex.Pattern url, java.lang.String text)Assert that responses content for all requests found by a given URL pattern contain specified value.AssertionResultassertAnyUrlContentDoesNotContain(java.util.regex.Pattern url, java.lang.String text)Assert that responses content for all requests found by a given URL pattern don't contain specified value.AssertionResultassertAnyUrlContentLengthLessThanOrEquals(java.util.regex.Pattern url, java.lang.Long maxSize)Assert that content length of all responses found by url pattern do not exceed max value.AssertionResultassertAnyUrlContentMatches(java.util.regex.Pattern url, java.util.regex.Pattern contentPattern)Assert that responses content for all requests found by url pattern matches content pattern.AssertionResultassertAnyUrlResponseHeaderContains(java.util.regex.Pattern url, java.lang.String value)Assert that headers of all responses found by url pattern contain specified value.AssertionResultassertAnyUrlResponseHeaderContains(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)Assert that if responses found by url pattern have headers with specified name - among them must be one header with value containing specified text.AssertionResultassertAnyUrlResponseHeaderDoesNotContain(java.util.regex.Pattern url, java.lang.String value)Assert that headers of all responses found by url pattern don't contain specified value.AssertionResultassertAnyUrlResponseHeaderDoesNotContain(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)Assert that if responses found by url pattern have headers with specified name - their values must not contain specified value.AssertionResultassertAnyUrlResponseHeaderMatches(java.util.regex.Pattern url, java.util.regex.Pattern namePattern, java.util.regex.Pattern valuePattern)Assert that if responses found by url pattern have headers with name found by name pattern - their values should match value pattern.AssertionResultassertMostRecentResponseContentContains(java.util.regex.Pattern url, java.lang.String text)Assert that response content for the most recent request found by a given URL pattern contains specified value.AssertionResultassertMostRecentResponseContentDoesNotContain(java.util.regex.Pattern url, java.lang.String text)Assert that response content for the most recent request found by a given URL pattern doesn't contain specified value.AssertionResultassertMostRecentResponseContentLengthLessThanOrEqual(java.util.regex.Pattern url, java.lang.Long max)Assert that content length of the most recent response found by url pattern does not exceed max value.AssertionResultassertMostRecentResponseContentMatches(java.util.regex.Pattern url, java.util.regex.Pattern contentPattern)Assert that response content for the most recent request found by a given URL pattern matches content pattern.AssertionResultassertMostRecentResponseHeaderContains(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)Assert that if the most recent response found by url pattern has header with specified name - it's value must contain specified text.AssertionResultassertMostRecentResponseHeaderDoesNotContain(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)Assert that if the most recent response found by url pattern has header with specified name - it's value must not contain specified text.AssertionResultassertMostRecentResponseHeaderMatches(java.util.regex.Pattern url, java.util.regex.Pattern name, java.util.regex.Pattern value)Assert that if the most recent response found by url pattern has header with name found by name pattern - it's value should match value pattern.AssertionResultassertMostRecentResponseStatusCode(HttpStatusClass clazz)Assert that the most recent response has status belonging to specified class.AssertionResultassertMostRecentResponseStatusCode(java.lang.Integer status)Assert that the most recent response has specified status.AssertionResultassertMostRecentResponseStatusCode(java.util.regex.Pattern url, HttpStatusClass clazz)Assert that the most recent response found by url pattern has status belonging to specified class.AssertionResultassertMostRecentResponseStatusCode(java.util.regex.Pattern url, java.lang.Integer status)Assert that the most recent response found by url pattern has specified status.AssertionResultassertMostRecentResponseTimeLessThanOrEqual(java.util.regex.Pattern url, long time)Assert that the response time for the most recent request found by a given URL pattern is less than or equal to a given number of milliseconds.AssertionResultassertResponseStatusCode(HttpStatusClass clazz)Assert that all responses of current step have statuses belonging to the same class.AssertionResultassertResponseStatusCode(java.lang.Integer status)Assert that all responses of current step have specified status.AssertionResultassertResponseStatusCode(java.util.regex.Pattern url, HttpStatusClass clazz)Assert that all responses found by url pattern have statuses belonging to the same class.AssertionResultassertResponseStatusCode(java.util.regex.Pattern url, java.lang.Integer status)Assert that all responses found by url pattern have specified http status.AssertionResultassertResponseTimeLessThanOrEqual(java.util.regex.Pattern url, long time)Assert that the response times for all requests found by a given URL pattern are less than or equal to a given number of milliseconds.voidautoAuthorization(java.lang.String domain, java.lang.String username, java.lang.String password, AuthType authType)Enables automatic authorization for the specified domain and auth type.voidblacklistRequests(java.lang.String pattern, int responseCode)Adds a URL-matching regular expression to the blacklist.voidblacklistRequests(java.lang.String pattern, int responseCode, java.lang.String method)Adds a URL-matching regular expression to the blacklist.voidchainedProxyAuthorization(java.lang.String username, java.lang.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).voidclearBlacklist()Clears any existing blacklist.voidclearRewriteRules()Clears all existing rewrite rules.voiddisableHarCaptureTypes(CaptureType... captureTypes)Disables the specified HAR capture types.voiddisableHarCaptureTypes(java.util.Set<CaptureType> captureTypes)Disables the specified HAR capture types.voiddisableWhitelist()Clears any existing whitelist and disables whitelisting.voidenableEmptyWhitelist(int statusCode)Enables the whitelist, but with no matching URLs.voidenableHarCaptureTypes(CaptureType... captureTypes)Enables the specified HAR capture types.voidenableHarCaptureTypes(java.util.Set<CaptureType> captureTypes)Enables the specified HAR capture types.HarendHar()Stops capturing traffic in the HAR.voidendPage()java.util.Collection<HarEntry>findEntries(java.util.regex.Pattern url)Search the entire log for entries whose request URL matches the givenurl.java.util.Optional<HarEntry>findMostRecentEntry(java.util.regex.Pattern url)Search the entire log for the most recent entry whose request URL matches the givenurl.java.util.Map<java.lang.String,java.lang.String>getAllHeaders()Returns all headers previously added withBrowserUpProxy.addHeader(String name, String value).java.util.Collection<BlacklistEntry>getBlacklist()Returns all blacklist entries currently in effect.java.net.InetSocketAddressgetChainedProxy()Returns the address and port of the upstream proxy.java.net.InetAddressgetClientBindAddress()Returns the address of the network interface on which the proxy is listening for client connections.HarPagegetCurrentHarPage()java.util.List<org.littleshoot.proxy.HttpFiltersSource>getFilterFactories()HargetHar()Retrieves the current HAR.HargetHar(boolean cleanHar)If cleanHar is false - returns current HAR.java.util.EnumSet<CaptureType>getHarCaptureTypes()AdvancedHostResolvergetHostNameResolver()Returns the current host name resolver.intgetPort()Returns the actual port on which the proxy is listening for client connections.longgetReadBandwidthLimit()Returns the current bandwidth limit for reading, in bytes per second.java.util.Map<java.lang.String,java.lang.String>getRewriteRules()Returns all rewrite rules currently in effect.java.net.InetAddressgetServerBindAddress()Returns the address address of the network interface the proxy will use to initiate upstream connections.intgetWhitelistStatusCode()Returns the status code returned for all URLs that do not match the whitelist.java.util.Collection<java.lang.String>getWhitelistUrls()Returns the URL-matching regular expressions currently in effect.longgetWriteBandwidthLimit()Returns the current bandwidth limit for writing, in bytes per second.booleanisMitmDisabled()booleanisStarted()Returns true if the proxy is started and listening for connections, otherwise false.booleanisStopped()booleanisWhitelistEnabled()Returns true if the whitelist is enabled, otherwise false.HarnewHar()Starts a new HAR file with the default page name (seeBrowserUpProxy.newPage().HarnewHar(java.lang.String initialPageRef)Starts a new HAR file with the specified initialPageRef as the page name and page title.HarnewHar(java.lang.String initialPageRef, java.lang.String initialPageTitle)Starts a new HAR file with the specified page name and page title.HarnewPage()Starts a new HAR page using the default page naming convention.HarnewPage(java.lang.String pageRef)Starts a new HAR page using the specified pageRef as the page name and the page title.HarnewPage(java.lang.String pageRef, java.lang.String pageTitle)Starts a new HAR page using the specified pageRef as the page name and the pageTitle as the page title.voidremoveAllHeaders()Removes all headers previously added withBrowserUpProxy.addHeader(String name, String value).voidremoveHeader(java.lang.String name)Removes a header previously added withBrowserUpProxy.addHeader(String name, String value).voidremoveRewriteRule(java.lang.String urlPattern)Removes an existing rewrite rule whose urlPattern matches the specified pattern.voidrewriteUrl(java.lang.String pattern, java.lang.String replace)Adds a rewrite rule for the specified URL-matching regular expression.voidrewriteUrls(java.util.Map<java.lang.String,java.lang.String> rewriteRules)Replaces existing rewrite rules with the specified patterns and replacement expressions.voidsetBlacklist(java.util.Collection<BlacklistEntry> blacklist)Replaces any existing blacklist with the specified blacklist.voidsetChainedProxy(java.net.InetSocketAddress chainedProxyAddress)Instructs this proxy to route traffic through an upstream proxy.voidsetChainedProxyHTTPS(boolean chainedProxyHTTPS)Instructs this proxy to route traffic through an upstream proxy using HTTPS.voidsetChainedProxyManager(org.littleshoot.proxy.ChainedProxyManager chainedProxyManager)Allows access to the LittleProxyChainedProxyManagerfor fine-grained control of the chained proxies.voidsetChainedProxyNonProxyHosts(java.util.List<java.lang.String> upstreamNonProxyHosts)Instructs this proxy to route traffic trough an upstream proxy but handling this addresses as exceptions (non proxy hosts)voidsetConnectTimeout(int connectTimeout, java.util.concurrent.TimeUnit timeUnit)Maximum amount of time to wait to establish a connection to a remote server.voidsetHarCaptureTypes(CaptureType... captureTypes)Sets the data types that will be captured in the HAR file for future requests.voidsetHarCaptureTypes(java.util.Set<CaptureType> harCaptureSettings)Sets the data types that will be captured in the HAR file for future requests.voidsetHostNameResolver(AdvancedHostResolver resolver)Sets the resolver that will be used to look up host names.voidsetIdleConnectionTimeout(int idleConnectionTimeout, java.util.concurrent.TimeUnit timeUnit)The LittleProxy implementation only allows idle connection timeouts to be specified in seconds.voidsetLatency(long latency, java.util.concurrent.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.voidsetMitmDisabled(boolean mitmDisabled)Completely disables MITM for this proxy server.voidsetMitmManager(org.littleshoot.proxy.MitmManager mitmManager)Sets the MITM manager, which is responsible for generating forged SSL certificates to present to clients.voidsetReadBandwidthLimit(long bytesPerSecond)Sets the maximum bandwidth to consume when reading server responses.voidsetRequestTimeout(int requestTimeout, java.util.concurrent.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.voidsetThreadPoolConfiguration(org.littleshoot.proxy.impl.ThreadPoolConfiguration threadPoolConfiguration)Configures the Netty thread pool used by the LittleProxy back-end.voidsetTrustAllServers(boolean trustAllServers)Disables verification of all upstream servers' SSL certificates.voidsetTrustSource(com.browserup.bup.mitm.TrustSource trustSource)Sets theTrustSourcethat contains trusted root certificate authorities that will be used to validate upstream servers' certificates.voidsetUseEcc(boolean useEcc)voidsetWriteBandwidthLimit(long bytesPerSecond)Sets the maximum bandwidth to consume when sending requests to servers.voidstart()Starts the proxy on port 0 (a JVM-selected open port).voidstart(int port)Starts the proxy on the specified port.voidstart(int port, java.net.InetAddress bindAddress)Starts the proxy on the specified port.voidstart(int port, java.net.InetAddress clientBindAddress, java.net.InetAddress serverBindAddress)Starts the proxy on the specified port.voidstop()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 voidstop(boolean graceful)voidstopAutoAuthorization(java.lang.String domain)Stops automatic authorization for the specified domain.booleanwaitForQuiescence(long quietPeriod, long timeout, java.util.concurrent.TimeUnit timeUnit)Waits for existing network traffic to stop, and for the specified quietPeriod to elapse.voidwhitelistRequests(java.lang.String[] patterns, int responseCode)Whitelist the specified request patterns, returning the specified responseCode for non-whitelisted requests.voidwhitelistRequests(java.util.Collection<java.lang.String> urlPatterns, int statusCode)Whitelists URLs matching the specified regular expression patterns.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.browserup.bup.BrowserUpProxy
assertAnyUrlResponseHeaderMatches, assertMostRecentResponseHeaderContains, assertMostRecentResponseHeaderDoesNotContain, assertMostRecentResponseHeaderMatches
-
-
-
-
Field Detail
-
DEFAULT_PAGE_REF
public static final java.lang.String DEFAULT_PAGE_REF
- See Also:
- Constant Field Values
-
DEFAULT_PAGE_TITLE
public static final java.lang.String DEFAULT_PAGE_TITLE
- See Also:
- Constant Field Values
-
VIA_HEADER_ALIAS
public static final java.lang.String VIA_HEADER_ALIAS
The default pseudonym to use when adding the Via header to proxied requests.- See Also:
- Constant Field Values
-
-
Method Detail
-
start
public void start(int port, java.net.InetAddress clientBindAddress, java.net.InetAddress serverBindAddress)Description copied from interface:BrowserUpProxyStarts the proxy on the specified port. The proxy will listen for connections on the network interface specified by the clientBindAddress, and will initiate connections to upstream servers from the network interface specified by the serverBindAddress.- Specified by:
startin interfaceBrowserUpProxy- Parameters:
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 servers
-
isStarted
public boolean isStarted()
Description copied from interface:BrowserUpProxyReturns true if the proxy is started and listening for connections, otherwise false.- Specified by:
isStartedin interfaceBrowserUpProxy- Returns:
- is proxy started
-
start
public void start(int port)
Description copied from interface:BrowserUpProxyStarts the proxy on the specified port. The proxy will bind the listener to the wildcard address (0:0:0:0 - all network interfaces).- Specified by:
startin interfaceBrowserUpProxy- Parameters:
port- port to listen on
-
start
public void start(int port, java.net.InetAddress bindAddress)Description copied from interface:BrowserUpProxyStarts the proxy on the specified port. The proxy will listen for connections on the network interface specified by the bindAddress, and will also initiate connections to upstream servers on the same network interface.- Specified by:
startin interfaceBrowserUpProxy- Parameters:
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.
-
start
public void start()
Description copied from interface:BrowserUpProxyStarts the proxy on port 0 (a JVM-selected open port). The proxy will bind the listener to the wildcard address (0:0:0:0 - all network interfaces).- Specified by:
startin interfaceBrowserUpProxy
-
stop
public void stop()
Description copied from interface:BrowserUpProxyStops accepting new client connections and initiates a graceful shutdown of the proxy server, waiting up to 5 seconds for network traffic to stop. If the proxy was previously stopped or aborted, this method has no effect.- Specified by:
stopin interfaceBrowserUpProxy
-
abort
public void abort()
Description copied from interface:BrowserUpProxyLikeBrowserUpProxy.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.- Specified by:
abortin interfaceBrowserUpProxy
-
stop
protected void stop(boolean graceful)
-
getClientBindAddress
public java.net.InetAddress getClientBindAddress()
Description copied from interface:BrowserUpProxyReturns the address of the network interface on which the proxy is listening for client connections.- Specified by:
getClientBindAddressin interfaceBrowserUpProxy- Returns:
- the client bind address, or null if the proxy has not been started
-
getPort
public int getPort()
Description copied from interface:BrowserUpProxyReturns the actual port on which the proxy is listening for client connections.- Specified by:
getPortin interfaceBrowserUpProxy- Returns:
- port
-
getServerBindAddress
public java.net.InetAddress getServerBindAddress()
Description copied from interface:BrowserUpProxyReturns the address address of the network interface the proxy will use to initiate upstream connections. If no server bind address has been set, this method returns null, even if the proxy has been started.- Specified by:
getServerBindAddressin interfaceBrowserUpProxy- Returns:
- server bind address if one has been set, otherwise null
-
getHar
public Har getHar()
Description copied from interface:BrowserUpProxyRetrieves the current HAR.- Specified by:
getHarin interfaceBrowserUpProxy- Returns:
- current HAR, or null if HAR capture is not enabled
-
getHar
public Har getHar(boolean cleanHar)
Description copied from interface:BrowserUpProxyIf cleanHar is false - returns current HAR. If cleanHar is true - cleans current HAR and returns HAR with data it has before cleaning.- Specified by:
getHarin interfaceBrowserUpProxy- Returns:
- current HAR, or null if HAR capture is not enabled
-
newHar
public Har newHar()
Description copied from interface:BrowserUpProxyStarts a new HAR file with the default page name (seeBrowserUpProxy.newPage(). Enables HAR capture if it was not previously enabled.- Specified by:
newHarin interfaceBrowserUpProxy- Returns:
- existing HAR file, or null if none exists or HAR capture was disabled
-
newHar
public Har newHar(java.lang.String initialPageRef)
Description copied from interface:BrowserUpProxyStarts a new HAR file with the specified initialPageRef as the page name and page title. Enables HAR capture if it was not previously enabled.- Specified by:
newHarin interfaceBrowserUpProxy- Parameters:
initialPageRef- initial page name of the new HAR file- Returns:
- existing HAR file, or null if none exists or HAR capture was disabled
-
newHar
public Har newHar(java.lang.String initialPageRef, java.lang.String initialPageTitle)
Description copied from interface:BrowserUpProxyStarts a new HAR file with the specified page name and page title. Enables HAR capture if it was not previously enabled.- Specified by:
newHarin interfaceBrowserUpProxy- Parameters:
initialPageRef- initial page name of the new HAR fileinitialPageTitle- initial page title of the new HAR file- Returns:
- existing HAR file, or null if none exists or HAR capture was disabled
-
setHarCaptureTypes
public void setHarCaptureTypes(java.util.Set<CaptureType> harCaptureSettings)
Description copied from interface:BrowserUpProxySets the data types that will be captured in the HAR file for future requests. Replaces any existing capture types with the specified capture types. A null or empty set will not disable HAR capture, but will disable collection of additionalCaptureTypedata types.CaptureTypeprovides several convenience methods to retrieve commonly-used capture settings. Note: HAR capture must still be explicitly enabled viaBrowserUpProxy.newHar()orBrowserUpProxy.newHar(String)to begin capturing any request and response contents.- Specified by:
setHarCaptureTypesin interfaceBrowserUpProxy- Parameters:
harCaptureSettings- HAR data types to capture
-
setHarCaptureTypes
public void setHarCaptureTypes(CaptureType... captureTypes)
Description copied from interface:BrowserUpProxySets the data types that will be captured in the HAR file for future requests. Replaces any existing capture types with the specified capture types. A null or empty set will not disable HAR capture, but will disable collection of additionalCaptureTypedata types.CaptureTypeprovides several convenience methods to retrieve commonly-used capture settings. Note: HAR capture must still be explicitly enabled viaBrowserUpProxy.newHar()orBrowserUpProxy.newHar(String)to begin capturing any request and response contents.- Specified by:
setHarCaptureTypesin interfaceBrowserUpProxy- Parameters:
captureTypes- HAR data types to capture
-
getHarCaptureTypes
public java.util.EnumSet<CaptureType> getHarCaptureTypes()
- Specified by:
getHarCaptureTypesin interfaceBrowserUpProxy- Returns:
- A copy of HAR capture types currently in effect. The EnumSet cannot be used to modify the HAR capture types currently in effect.
-
enableHarCaptureTypes
public void enableHarCaptureTypes(java.util.Set<CaptureType> captureTypes)
Description copied from interface:BrowserUpProxyEnables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Specified by:
enableHarCaptureTypesin interfaceBrowserUpProxy- Parameters:
captureTypes- capture types to enable
-
enableHarCaptureTypes
public void enableHarCaptureTypes(CaptureType... captureTypes)
Description copied from interface:BrowserUpProxyEnables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Specified by:
enableHarCaptureTypesin interfaceBrowserUpProxy- Parameters:
captureTypes- capture types to enable
-
disableHarCaptureTypes
public void disableHarCaptureTypes(java.util.Set<CaptureType> captureTypes)
Description copied from interface:BrowserUpProxyDisables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Specified by:
disableHarCaptureTypesin interfaceBrowserUpProxy- Parameters:
captureTypes- capture types to disable
-
disableHarCaptureTypes
public void disableHarCaptureTypes(CaptureType... captureTypes)
Description copied from interface:BrowserUpProxyDisables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Specified by:
disableHarCaptureTypesin interfaceBrowserUpProxy- Parameters:
captureTypes- capture types to disable
-
newPage
public Har newPage()
Description copied from interface:BrowserUpProxyStarts a new HAR page using the default page naming convention. The default page naming convention is "Page #", where "#" resets to 1 every timeBrowserUpProxy.newHar()orBrowserUpProxy.newHar(String)is called, and increments on every subsequent call toBrowserUpProxy.newPage()orBrowserUpProxy.newHar(String). Populates theHarPageTiming.onLoadvalue based on the amount of time the current page has been captured.- Specified by:
newPagein interfaceBrowserUpProxy- Returns:
- the HAR as it existed immediately after ending the current page
-
newPage
public Har newPage(java.lang.String pageRef)
Description copied from interface:BrowserUpProxyStarts a new HAR page using the specified pageRef as the page name and the page title. Populates theHarPageTiming.onLoadvalue based on the amount of time the current page has been captured.- Specified by:
newPagein interfaceBrowserUpProxy- Parameters:
pageRef- name of the new page- Returns:
- the HAR as it existed immediately after ending the current page
-
newPage
public Har newPage(java.lang.String pageRef, java.lang.String pageTitle)
Description copied from interface:BrowserUpProxyStarts a new HAR page using the specified pageRef as the page name and the pageTitle as the page title. Populates theHarPageTiming.onLoadvalue based on the amount of time the current page has been captured.- Specified by:
newPagein interfaceBrowserUpProxy- Parameters:
pageRef- name of the new pagepageTitle- title of the new page- Returns:
- the HAR as it existed immediately after ending the current page
-
endHar
public Har endHar()
Description copied from interface:BrowserUpProxyStops capturing traffic in the HAR. Populates theHarPageTiming.onLoadvalue for the current page based on the amount of time it has been captured.- Specified by:
endHarin interfaceBrowserUpProxy- Returns:
- the existing HAR
-
setReadBandwidthLimit
public void setReadBandwidthLimit(long bytesPerSecond)
Description copied from interface:BrowserUpProxySets the maximum bandwidth to consume when reading server responses.- Specified by:
setReadBandwidthLimitin interfaceBrowserUpProxy- Parameters:
bytesPerSecond- maximum bandwidth, in bytes per second
-
getReadBandwidthLimit
public long getReadBandwidthLimit()
Description copied from interface:BrowserUpProxyReturns the current bandwidth limit for reading, in bytes per second.- Specified by:
getReadBandwidthLimitin interfaceBrowserUpProxy- Returns:
- ReadBandwidthLimit
-
setWriteBandwidthLimit
public void setWriteBandwidthLimit(long bytesPerSecond)
Description copied from interface:BrowserUpProxySets the maximum bandwidth to consume when sending requests to servers.- Specified by:
setWriteBandwidthLimitin interfaceBrowserUpProxy- Parameters:
bytesPerSecond- maximum bandwidth, in bytes per second
-
getWriteBandwidthLimit
public long getWriteBandwidthLimit()
Description copied from interface:BrowserUpProxyReturns the current bandwidth limit for writing, in bytes per second.- Specified by:
getWriteBandwidthLimitin interfaceBrowserUpProxy- Returns:
- WriteBandwidthLimit
-
endPage
public void endPage()
-
addHeaders
public void addHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Description copied from interface:BrowserUpProxyAdds the specified HTTP headers to every request. Replaces any existing additional headers with the specified headers.- Specified by:
addHeadersin interfaceBrowserUpProxy- Parameters:
headers-Map<header name, header value>to append to every request.
-
setLatency
public void setLatency(long latency, java.util.concurrent.TimeUnit timeUnit)Description copied from interface:BrowserUpProxyThe 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.- Specified by:
setLatencyin interfaceBrowserUpProxy- Parameters:
latency- minimum latency, or 0 for no minimumtimeUnit- TimeUnit for the latency
-
autoAuthorization
public void autoAuthorization(java.lang.String domain, java.lang.String username, java.lang.String password, AuthType authType)Description copied from interface:BrowserUpProxyEnables automatic authorization for the specified domain and auth type. Every request sent to the specified domain will contain the specified authorization information.- Specified by:
autoAuthorizationin interfaceBrowserUpProxy- Parameters:
domain- domain automatically send authorization information tousername- authorization usernamepassword- authorization passwordauthType- authorization type
-
stopAutoAuthorization
public void stopAutoAuthorization(java.lang.String domain)
Description copied from interface:BrowserUpProxyStops automatic authorization for the specified domain.- Specified by:
stopAutoAuthorizationin interfaceBrowserUpProxy- Parameters:
domain- domain to stop automatically sending authorization information to
-
chainedProxyAuthorization
public void chainedProxyAuthorization(java.lang.String username, java.lang.String password, AuthType authType)Description copied from interface:BrowserUpProxyEnables chained proxy authorization using the Proxy-Authorization header described in RFC 7235, section 4.4 (https://tools.ietf.org/html/rfc7235#section-4.4). Currently, onlyAuthType.BASICauthentication is supported.- Specified by:
chainedProxyAuthorizationin interfaceBrowserUpProxy- Parameters:
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)
-
setConnectTimeout
public void setConnectTimeout(int connectTimeout, java.util.concurrent.TimeUnit timeUnit)Description copied from interface:BrowserUpProxyMaximum amount of time to wait to establish a connection to a remote server. If the connection has not been established within the specified time, the proxy will respond with an HTTP 502 Bad Gateway. The default value is 60 seconds.- Specified by:
setConnectTimeoutin interfaceBrowserUpProxy- Parameters:
connectTimeout- maximum time to wait to establish a connection to a server, or 0 to wait indefinitelytimeUnit- TimeUnit for the connectionTimeout
-
setIdleConnectionTimeout
public void setIdleConnectionTimeout(int idleConnectionTimeout, java.util.concurrent.TimeUnit timeUnit)The LittleProxy implementation only allows idle connection timeouts to be specified in seconds. idleConnectionTimeouts greater than 0 but less than 1 second will be set to 1 second; otherwise, values will be truncated (i.e. 1500ms will become 1s).- Specified by:
setIdleConnectionTimeoutin interfaceBrowserUpProxy- Parameters:
idleConnectionTimeout- maximum time to allow a connection to remain idle, or 0 to wait indefinitely.timeUnit- TimeUnit for the idleConnectionTimeout
-
setRequestTimeout
public void setRequestTimeout(int requestTimeout, java.util.concurrent.TimeUnit timeUnit)Description copied from interface:BrowserUpProxyMaximum amount of time to wait for an HTTP response from the remote server after the request has been sent in its entirety. The HTTP request must complete within the specified time. If the proxy has not yet begun to forward the response to the client, the proxy will respond with an HTTP 504 Gateway Timeout. If the proxy has already started forwarding the response to the client, the connection to the client may be closed abruptly. The default value is 0 (wait indefinitely).- Specified by:
setRequestTimeoutin interfaceBrowserUpProxy- Parameters:
requestTimeout- maximum time to wait for an HTTP response, or 0 to wait indefinitelytimeUnit- TimeUnit for the requestTimeout
-
rewriteUrl
public void rewriteUrl(java.lang.String pattern, java.lang.String replace)Description copied from interface:BrowserUpProxyAdds a rewrite rule for the specified URL-matching regular expression. If there are any existing rewrite rules, the new rewrite rule will be applied last, after all other rewrite rules are applied. The specified urlPattern will be replaced with the specified replacement expression. The urlPattern is treated as a Java regular expression and must be properly escaped (seePattern). The replacementExpression may consist of capture groups specified in the urlPattern, denoted by a $ (seeMatcher.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 (useBrowserUpProxy.getHostNameResolver()andAdvancedHostResolver.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 matchhttp://www.website.com:80/page. For example, the following rewrite rule:
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:proxy.rewriteUrl("http://www\\.(yahoo|bing)\\.com/\\?(\\w+)=(\\w+)", "http://www.google.com/?originalDomain=$1&$2=$3");
will result in the proxy making a request to:http://www.yahoo.com?theFirstParam=someValue
When applied to the URL:http://www.google.com?originalDomain=yahoo&theFirstParam=someValue
will result in the proxy making a request to:http://www.bing.com?anotherParam=anotherValuehttp://www.google.com?originalDomain=bing&anotherParam=anotherValue- Specified by:
rewriteUrlin interfaceBrowserUpProxy- Parameters:
pattern- URL-matching regular expressionreplace- an expression, which may optionally contain capture groups, which will replace any URL which matches urlPattern
-
rewriteUrls
public void rewriteUrls(java.util.Map<java.lang.String,java.lang.String> rewriteRules)
Description copied from interface:BrowserUpProxyReplaces existing rewrite rules with the specified patterns and replacement expressions. The rules will be applied in the order specified by the Map's iterator. SeeBrowserUpProxy.rewriteUrl(String, String)for details on the format of the rewrite rules.- Specified by:
rewriteUrlsin interfaceBrowserUpProxy- Parameters:
rewriteRules-Map<urlPattern, replacementExpression>
-
clearRewriteRules
public void clearRewriteRules()
Description copied from interface:BrowserUpProxyClears all existing rewrite rules.- Specified by:
clearRewriteRulesin interfaceBrowserUpProxy
-
blacklistRequests
public void blacklistRequests(java.lang.String pattern, int responseCode)Description copied from interface:BrowserUpProxyAdds a URL-matching regular expression to the blacklist. Requests that match a blacklisted URL will return the specified HTTP statusCode for all HTTP methods. If there are existing patterns on the blacklist, the urlPattern will be evaluated last, after the URL is checked against all other blacklist entries. The urlPattern matches the full URL of the request, including scheme, host, and port, path, and query parameters for both HTTP and HTTPS requests. For example, to blacklist both HTTP and HTTPS requests to www.google.com, use a urlPattern of "https?://www\\.google\\.com/.*".- Specified by:
blacklistRequestsin interfaceBrowserUpProxy- Parameters:
pattern- URL-matching regular expression to blacklistresponseCode- HTTP status code to return
-
blacklistRequests
public void blacklistRequests(java.lang.String pattern, int responseCode, java.lang.String method)Description copied from interface:BrowserUpProxyAdds a URL-matching regular expression to the blacklist. Requests that match a blacklisted URL will return the specified HTTP statusCode only when the request's HTTP method (GET, POST, PUT, etc.) matches the specified httpMethodPattern regular expression. If there are existing patterns on the blacklist, the urlPattern will be evaluated last, after the URL is checked against all other blacklist entries. SeeBrowserUpProxy.blacklistRequests(String, int)for details on the URL the urlPattern will match.- Specified by:
blacklistRequestsin interfaceBrowserUpProxy- Parameters:
pattern- URL-matching regular expression to blacklistresponseCode- HTTP status code to returnmethod- regular expression matching a request's HTTP method
-
setBlacklist
public void setBlacklist(java.util.Collection<BlacklistEntry> blacklist)
Description copied from interface:BrowserUpProxyReplaces any existing blacklist with the specified blacklist. URLs will be evaluated against the blacklist in the order specified by the Collection's iterator.- Specified by:
setBlacklistin interfaceBrowserUpProxy- Parameters:
blacklist- new blacklist entries
-
getBlacklist
public java.util.Collection<BlacklistEntry> getBlacklist()
Description copied from interface:BrowserUpProxyReturns all blacklist entries currently in effect. Iterating over the returned Collection is guaranteed to return blacklist entries in the order in which URLs are actually evaluated against the blacklist.- Specified by:
getBlacklistin interfaceBrowserUpProxy- Returns:
- blacklist entries, or an empty collection if none exist
-
isWhitelistEnabled
public boolean isWhitelistEnabled()
Description copied from interface:BrowserUpProxyReturns true if the whitelist is enabled, otherwise false.- Specified by:
isWhitelistEnabledin interfaceBrowserUpProxy- Returns:
- is WhitelistEnabled
-
getWhitelistUrls
public java.util.Collection<java.lang.String> getWhitelistUrls()
Description copied from interface:BrowserUpProxyReturns the URL-matching regular expressions currently in effect. If the whitelist is disabled, this method always returns an empty collection. If the whitelist is enabled but empty, this method return an empty collection.- Specified by:
getWhitelistUrlsin interfaceBrowserUpProxy- Returns:
- whitelist currently in effect, or an empty collection if the whitelist is disabled or empty
-
getWhitelistStatusCode
public int getWhitelistStatusCode()
Description copied from interface:BrowserUpProxyReturns the status code returned for all URLs that do not match the whitelist. If the whitelist is not currently enabled, returns -1.- Specified by:
getWhitelistStatusCodein interfaceBrowserUpProxy- Returns:
- HTTP status code returned for non-whitelisted URLs, or -1 if the whitelist is disabled.
-
clearBlacklist
public void clearBlacklist()
Description copied from interface:BrowserUpProxyClears any existing blacklist.- Specified by:
clearBlacklistin interfaceBrowserUpProxy
-
whitelistRequests
public void whitelistRequests(java.util.Collection<java.lang.String> urlPatterns, int statusCode)Description copied from interface:BrowserUpProxyWhitelists URLs matching the specified regular expression patterns. Replaces any existing whitelist. The urlPattern matches the full URL of the request, including scheme, host, and port, path, and query parameters for both HTTP and HTTPS requests. For example, to whitelist both HTTP and HTTPS requests to www.google.com, use a urlPattern of "https?://www\\.google\\.com/.*". Note: All HTTP CONNECT requests are automatically whitelisted and cannot be short-circuited using the whitelist response code.- Specified by:
whitelistRequestsin interfaceBrowserUpProxy- Parameters:
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 pattern
-
addWhitelistPattern
public void addWhitelistPattern(java.lang.String urlPattern)
Description copied from interface:BrowserUpProxyAdds a URL-matching regular expression to an existing whitelist.- Specified by:
addWhitelistPatternin interfaceBrowserUpProxy- Parameters:
urlPattern- URL-matching regular expressions to whitelist
-
whitelistRequests
public void whitelistRequests(java.lang.String[] patterns, int responseCode)Whitelist the specified request patterns, returning the specified responseCode for non-whitelisted requests.- Parameters:
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 requests
-
enableEmptyWhitelist
public void enableEmptyWhitelist(int statusCode)
Description copied from interface:BrowserUpProxyEnables the whitelist, but with no matching URLs. All requests will generated the specified HTTP statusCode.- Specified by:
enableEmptyWhitelistin interfaceBrowserUpProxy- Parameters:
statusCode- HTTP status code to return to clients on all requests
-
disableWhitelist
public void disableWhitelist()
Description copied from interface:BrowserUpProxyClears any existing whitelist and disables whitelisting.- Specified by:
disableWhitelistin interfaceBrowserUpProxy
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)Description copied from interface:BrowserUpProxyAdds a new HTTP header to every request. If the header already exists on the request, it will be replaced with the specified header.- Specified by:
addHeaderin interfaceBrowserUpProxy- Parameters:
name- name of the header to addvalue- new header's value
-
removeHeader
public void removeHeader(java.lang.String name)
Description copied from interface:BrowserUpProxyRemoves a header previously added withBrowserUpProxy.addHeader(String name, String value).- Specified by:
removeHeaderin interfaceBrowserUpProxy- Parameters:
name- previously-added header's name
-
removeAllHeaders
public void removeAllHeaders()
Description copied from interface:BrowserUpProxyRemoves all headers previously added withBrowserUpProxy.addHeader(String name, String value).- Specified by:
removeAllHeadersin interfaceBrowserUpProxy
-
getAllHeaders
public java.util.Map<java.lang.String,java.lang.String> getAllHeaders()
Description copied from interface:BrowserUpProxyReturns all headers previously added withBrowserUpProxy.addHeader(String name, String value).- Specified by:
getAllHeadersin interfaceBrowserUpProxy- Returns:
Map<header name, header value>
-
setHostNameResolver
public void setHostNameResolver(AdvancedHostResolver resolver)
Description copied from interface:BrowserUpProxySets the resolver that will be used to look up host names. To chain multiple resolvers, wrap a list of resolvers in aChainedHostResolver.- Specified by:
setHostNameResolverin interfaceBrowserUpProxy- Parameters:
resolver- host name resolver
-
getHostNameResolver
public AdvancedHostResolver getHostNameResolver()
Description copied from interface:BrowserUpProxyReturns the current host name resolver.- Specified by:
getHostNameResolverin interfaceBrowserUpProxy- Returns:
- current host name resolver
-
waitForQuiescence
public boolean waitForQuiescence(long quietPeriod, long timeout, java.util.concurrent.TimeUnit timeUnit)Description copied from interface:BrowserUpProxyWaits for existing network traffic to stop, and for the specified quietPeriod to elapse. Returns true if there is no network traffic for the quiet period within the specified timeout, otherwise returns false.- Specified by:
waitForQuiescencein interfaceBrowserUpProxy- Parameters:
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 timeout- Returns:
- true if network traffic is stopped, otherwise false
-
setChainedProxy
public void setChainedProxy(java.net.InetSocketAddress chainedProxyAddress)
Instructs this proxy to route traffic through an upstream proxy. Note: UsingsetChainedProxyManager(ChainedProxyManager)will supersede any value set by this method. A chained proxy must be set before the proxy is started, though it can be changed after the proxy is started.- Specified by:
setChainedProxyin interfaceBrowserUpProxy- Parameters:
chainedProxyAddress- address of the upstream proxy
-
setChainedProxyHTTPS
public void setChainedProxyHTTPS(boolean chainedProxyHTTPS)
Description copied from interface:BrowserUpProxyInstructs this proxy to route traffic through an upstream proxy using HTTPS.- Specified by:
setChainedProxyHTTPSin interfaceBrowserUpProxy- Parameters:
chainedProxyHTTPS- address of the upstream proxy
-
getChainedProxy
public java.net.InetSocketAddress getChainedProxy()
Description copied from interface:BrowserUpProxyReturns the address and port of the upstream proxy.- Specified by:
getChainedProxyin interfaceBrowserUpProxy- Returns:
- address and port of the upstream proxy, or null of there is none.
-
setChainedProxyManager
public void setChainedProxyManager(org.littleshoot.proxy.ChainedProxyManager chainedProxyManager)
Allows access to the LittleProxyChainedProxyManagerfor fine-grained control of the chained proxies. To enable a single chained proxy,BrowserUpProxy.setChainedProxy(InetSocketAddress)is generally more convenient. Note: The chained proxy manager must be enabled before callingstart().- Parameters:
chainedProxyManager- chained proxy manager to enable
-
setChainedProxyNonProxyHosts
public void setChainedProxyNonProxyHosts(java.util.List<java.lang.String> upstreamNonProxyHosts)
Description copied from interface:BrowserUpProxyInstructs this proxy to route traffic trough an upstream proxy but handling this addresses as exceptions (non proxy hosts)- Specified by:
setChainedProxyNonProxyHostsin interfaceBrowserUpProxy- Parameters:
upstreamNonProxyHosts- non proxy hosts also called proxy exceptions
-
setThreadPoolConfiguration
public void setThreadPoolConfiguration(org.littleshoot.proxy.impl.ThreadPoolConfiguration threadPoolConfiguration)
Configures the Netty thread pool used by the LittleProxy back-end. SeeThreadPoolConfigurationfor details.- Parameters:
threadPoolConfiguration- thread pool configuration to use
-
addFirstHttpFilterFactory
public void addFirstHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
Description copied from interface:BrowserUpProxyAdds a new filter factory (request/response interceptor) to the beginning of the HttpFilters chain. Usage note: The actual filter (interceptor) instance is created on every request by implementing theHttpFiltersSource.filterRequest(io.netty.handler.codec.http.HttpRequest, io.netty.channel.ChannelHandlerContext)method and returning anHttpFiltersinstance (typically, a subclass ofHttpFiltersAdapter). To disable or bypass a filter on a per-request basis, the filterRequest() method may return null.- Specified by:
addFirstHttpFilterFactoryin interfaceBrowserUpProxy- Parameters:
filterFactory- factory to generate HttpFilters
-
addLastHttpFilterFactory
public void addLastHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
Description copied from interface:BrowserUpProxyAdds a new filter factory (request/response interceptor) to the end of the HttpFilters chain. Usage note: The actual filter (interceptor) instance is created on every request by implementing theHttpFiltersSource.filterRequest(io.netty.handler.codec.http.HttpRequest, io.netty.channel.ChannelHandlerContext)method and returning anHttpFiltersinstance (typically, a subclass ofHttpFiltersAdapter). To disable or bypass a filter on a per-request basis, the filterRequest() method may return null.- Specified by:
addLastHttpFilterFactoryin interfaceBrowserUpProxy- Parameters:
filterFactory- factory to generate HttpFilters
-
addResponseFilter
public void addResponseFilter(ResponseFilter filter)
Note: The current implementation of this method forces a maximum response size of 2 MiB. To adjust the maximum response size, or to disable aggregation (which disallows access to theHttpMessageContents), you may add the filter source directly:addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter, bufferSizeInBytes));- Specified by:
addResponseFilterin interfaceBrowserUpProxy- Parameters:
filter- filter instance
-
addRequestFilter
public void addRequestFilter(RequestFilter filter)
Note: The current implementation of this method forces a maximum request size of 2 MiB. To adjust the maximum request size, or to disable aggregation (which disallows access to theHttpMessageContents), you may add the filter source directly:addFirstHttpFilterFactory(new RequestFilterAdapter.FilterSource(filter, bufferSizeInBytes));- Specified by:
addRequestFilterin interfaceBrowserUpProxy- Parameters:
filter- filter instance
-
getRewriteRules
public java.util.Map<java.lang.String,java.lang.String> getRewriteRules()
Description copied from interface:BrowserUpProxyReturns all rewrite rules currently in effect. Iterating over the returned Map is guaranteed to return rewrite rules in the order in which the rules are actually applied.- Specified by:
getRewriteRulesin interfaceBrowserUpProxy- Returns:
Map<URL-matching regex, replacement expression>
-
removeRewriteRule
public void removeRewriteRule(java.lang.String urlPattern)
Description copied from interface:BrowserUpProxyRemoves an existing rewrite rule whose urlPattern matches the specified pattern.- Specified by:
removeRewriteRulein interfaceBrowserUpProxy- Parameters:
urlPattern- rewrite rule pattern to remove
-
isStopped
public boolean isStopped()
-
getCurrentHarPage
public HarPage getCurrentHarPage()
-
addHttpFilterFactory
public void addHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
-
getFilterFactories
public java.util.List<org.littleshoot.proxy.HttpFiltersSource> getFilterFactories()
-
setMitmDisabled
public void setMitmDisabled(boolean mitmDisabled) throws java.lang.IllegalStateExceptionDescription copied from interface:BrowserUpProxyCompletely disables MITM for this proxy server. The proxy will no longer intercept HTTPS requests, but they will still be pass-through proxied. This option must be set before the proxy is started; otherwise an IllegalStateException will be thrown.- Specified by:
setMitmDisabledin interfaceBrowserUpProxy- Parameters:
mitmDisabled- when true, MITM capture will be disabled- Throws:
java.lang.IllegalStateException- if the proxy is already started
-
setMitmManager
public void setMitmManager(org.littleshoot.proxy.MitmManager mitmManager)
Description copied from interface:BrowserUpProxySets the MITM manager, which is responsible for generating forged SSL certificates to present to clients. By default, BrowserUp Proxy uses the ca-certificate-rsa.cer root certificate for impersonation. See the documentation atImpersonatingMitmManagerandImpersonatingMitmManager.Builderfor details on customizing the root and server certificate generation.- Specified by:
setMitmManagerin interfaceBrowserUpProxy- Parameters:
mitmManager- MITM manager to use
-
setTrustAllServers
public void setTrustAllServers(boolean trustAllServers)
Description copied from interface:BrowserUpProxyDisables verification of all upstream servers' SSL certificates. All upstream servers will be trusted, even if they do not present valid certificates signed by certification authorities in the JDK's trust store. This option exposes the proxy to MITM attacks and should only be used when testing in trusted environments.- Specified by:
setTrustAllServersin interfaceBrowserUpProxy- Parameters:
trustAllServers- when true, disables upstream server certificate verification
-
setTrustSource
public void setTrustSource(com.browserup.bup.mitm.TrustSource trustSource)
Description copied from interface:BrowserUpProxySets theTrustSourcethat contains trusted root certificate authorities that will be used to validate upstream servers' certificates. When null, disables certificate validation (see warning atBrowserUpProxy.setTrustAllServers(boolean)).- Specified by:
setTrustSourcein interfaceBrowserUpProxy- Parameters:
trustSource- TrustSource containing root CAs, or null to disable upstream server validation
-
findMostRecentEntry
public java.util.Optional<HarEntry> findMostRecentEntry(java.util.regex.Pattern url)
Description copied from interface:BrowserUpProxySearch the entire log for the most recent entry whose request URL matches the givenurl.- Specified by:
findMostRecentEntryin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. URLs are formatted as: scheme://host:port/path?querystring. Port is not included in the URL if it is the standard port for the scheme. Fragments (example.com/#fragment) should not be included in the URL. If more than one URL found, return the most recently requested URL. Pattern examples: - Match a URL with "http" or "https" protocol, "example.com" domain, and "/index.html" exact file path, with no query parameters: "^(http|https)://example\\.com/index\\.html$" - Match a URL with "http" protocol, "example.com" domain, "/customer" exact path, followed by any query string: "^http://example\\.com/customer\\?.*" - Match a URL with "http" protocol, "example.com" domain, "/products" path, and exactly 1 UUID query parameter named "id": "^http://example\\.com/products\\?id=[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}$"- Returns:
HarEntryfor the most recently requested URL matching the givenurlpattern.
-
findEntries
public java.util.Collection<HarEntry> findEntries(java.util.regex.Pattern url)
Description copied from interface:BrowserUpProxySearch the entire log for entries whose request URL matches the givenurl.- Specified by:
findEntriesin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. URLs are formatted as: scheme://host:port/path?querystring. Port is not included in the URL if it is the standard port for the scheme. Fragments (example.com/#fragment) should not be included in the URL. If more than one URL found, use the most recently requested URL. Pattern examples: - Match a URL with "http" or "https" protocol, "example.com" domain, and "/index.html" exact file path, with no query parameters: "^(http|https)://example\\.com/index\\.html$" - Match a URL with "http" protocol, "example.com" domain, "/customer" exact path, followed by any query string: "^http://example\\.com/customer\\?.*" - Match a URL with "http" protocol, "example.com" domain, "/products" path, and exactly 1 UUID query parameter named "id": "^http://example\\.com/products\\?id=[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}$"- Returns:
- A list of
HarEntryfor any requests whose URL matches the givenurlpattern, or an empty list if none match.
-
assertMostRecentResponseTimeLessThanOrEqual
public AssertionResult assertMostRecentResponseTimeLessThanOrEqual(java.util.regex.Pattern url, long time)
Description copied from interface:BrowserUpProxyAssert that the response time for the most recent request found by a given URL pattern is less than or equal to a given number of milliseconds.- Specified by:
assertMostRecentResponseTimeLessThanOrEqualin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)time- Maximum time in milliseconds, inclusive.- Returns:
- Assertion result
-
assertResponseTimeLessThanOrEqual
public AssertionResult assertResponseTimeLessThanOrEqual(java.util.regex.Pattern url, long time)
Description copied from interface:BrowserUpProxyAssert that the response times for all requests found by a given URL pattern are less than or equal to a given number of milliseconds.- Specified by:
assertResponseTimeLessThanOrEqualin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)time- Maximum time in milliseconds, inclusive.- Returns:
- Assertion result
-
assertMostRecentResponseContentContains
public AssertionResult assertMostRecentResponseContentContains(java.util.regex.Pattern url, java.lang.String text)
Description copied from interface:BrowserUpProxyAssert that response content for the most recent request found by a given URL pattern contains specified value.- Specified by:
assertMostRecentResponseContentContainsin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)text- String to search in the content- Returns:
- Assertion result
-
assertMostRecentResponseContentDoesNotContain
public AssertionResult assertMostRecentResponseContentDoesNotContain(java.util.regex.Pattern url, java.lang.String text)
Description copied from interface:BrowserUpProxyAssert that response content for the most recent request found by a given URL pattern doesn't contain specified value.- Specified by:
assertMostRecentResponseContentDoesNotContainin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)text- String to search in the content- Returns:
- Assertion result
-
assertMostRecentResponseContentMatches
public AssertionResult assertMostRecentResponseContentMatches(java.util.regex.Pattern url, java.util.regex.Pattern contentPattern)
Description copied from interface:BrowserUpProxyAssert that response content for the most recent request found by a given URL pattern matches content pattern.- Specified by:
assertMostRecentResponseContentMatchesin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)contentPattern- Regular expression match of content to find.- Returns:
- Assertion result
-
assertAnyUrlContentLengthLessThanOrEquals
public AssertionResult assertAnyUrlContentLengthLessThanOrEquals(java.util.regex.Pattern url, java.lang.Long maxSize)
Description copied from interface:BrowserUpProxyAssert that content length of all responses found by url pattern do not exceed max value.- Specified by:
assertAnyUrlContentLengthLessThanOrEqualsin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)maxSize- Max length of content, inclusive- Returns:
- Assertion result
-
assertAnyUrlContentMatches
public AssertionResult assertAnyUrlContentMatches(java.util.regex.Pattern url, java.util.regex.Pattern contentPattern)
Description copied from interface:BrowserUpProxyAssert that responses content for all requests found by url pattern matches content pattern.- Specified by:
assertAnyUrlContentMatchesin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)contentPattern- Regular expression match of content to find.- Returns:
- Assertion result
-
assertAnyUrlContentContains
public AssertionResult assertAnyUrlContentContains(java.util.regex.Pattern url, java.lang.String text)
Description copied from interface:BrowserUpProxyAssert that responses content for all requests found by a given URL pattern contain specified value.- Specified by:
assertAnyUrlContentContainsin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)text- String to search in the content- Returns:
- Assertion result
-
assertAnyUrlContentDoesNotContain
public AssertionResult assertAnyUrlContentDoesNotContain(java.util.regex.Pattern url, java.lang.String text)
Description copied from interface:BrowserUpProxyAssert that responses content for all requests found by a given URL pattern don't contain specified value.- Specified by:
assertAnyUrlContentDoesNotContainin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)text- String to search in the content- Returns:
- Assertion result
-
assertAnyUrlResponseHeaderContains
public AssertionResult assertAnyUrlResponseHeaderContains(java.util.regex.Pattern url, java.lang.String value)
Description copied from interface:BrowserUpProxyAssert that headers of all responses found by url pattern contain specified value.- Specified by:
assertAnyUrlResponseHeaderContainsin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)value- Header value- Returns:
- Assertion result
-
assertAnyUrlResponseHeaderContains
public AssertionResult assertAnyUrlResponseHeaderContains(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)
Description copied from interface:BrowserUpProxyAssert that if responses found by url pattern have headers with specified name - among them must be one header with value containing specified text.- Specified by:
assertAnyUrlResponseHeaderContainsin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)name- Header namevalue- Header value- Returns:
- Assertion result
-
assertAnyUrlResponseHeaderDoesNotContain
public AssertionResult assertAnyUrlResponseHeaderDoesNotContain(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)
Description copied from interface:BrowserUpProxyAssert that if responses found by url pattern have headers with specified name - their values must not contain specified value.- Specified by:
assertAnyUrlResponseHeaderDoesNotContainin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)name- Header namevalue- Header value- Returns:
- Assertion result
-
assertAnyUrlResponseHeaderDoesNotContain
public AssertionResult assertAnyUrlResponseHeaderDoesNotContain(java.util.regex.Pattern url, java.lang.String value)
Description copied from interface:BrowserUpProxyAssert that headers of all responses found by url pattern don't contain specified value.- Specified by:
assertAnyUrlResponseHeaderDoesNotContainin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)value- Header value- Returns:
- Assertion result
-
assertAnyUrlResponseHeaderMatches
public AssertionResult assertAnyUrlResponseHeaderMatches(java.util.regex.Pattern url, java.util.regex.Pattern namePattern, java.util.regex.Pattern valuePattern)
Description copied from interface:BrowserUpProxyAssert that if responses found by url pattern have headers with name found by name pattern - their values should match value pattern.- Specified by:
assertAnyUrlResponseHeaderMatchesin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)namePattern- Regular expression match of header name to find.valuePattern- Regular expression match of header value.- Returns:
- Assertion result
-
assertResponseStatusCode
public AssertionResult assertResponseStatusCode(java.lang.Integer status)
Description copied from interface:BrowserUpProxyAssert that all responses of current step have specified status.- Specified by:
assertResponseStatusCodein interfaceBrowserUpProxy- Parameters:
status- Expected http status- Returns:
- Assertion result
-
assertResponseStatusCode
public AssertionResult assertResponseStatusCode(HttpStatusClass clazz)
Description copied from interface:BrowserUpProxyAssert that all responses of current step have statuses belonging to the same class.- Specified by:
assertResponseStatusCodein interfaceBrowserUpProxy- Parameters:
clazz- Http status class- Returns:
- Assertion result
-
assertResponseStatusCode
public AssertionResult assertResponseStatusCode(java.util.regex.Pattern url, java.lang.Integer status)
Description copied from interface:BrowserUpProxyAssert that all responses found by url pattern have specified http status.- Specified by:
assertResponseStatusCodein interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)status- Http status- Returns:
- Assertion result
-
assertResponseStatusCode
public AssertionResult assertResponseStatusCode(java.util.regex.Pattern url, HttpStatusClass clazz)
Description copied from interface:BrowserUpProxyAssert that all responses found by url pattern have statuses belonging to the same class.- Specified by:
assertResponseStatusCodein interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)clazz- Http status class- Returns:
- Assertion result
-
assertMostRecentResponseStatusCode
public AssertionResult assertMostRecentResponseStatusCode(java.lang.Integer status)
Description copied from interface:BrowserUpProxyAssert that the most recent response has specified status.- Specified by:
assertMostRecentResponseStatusCodein interfaceBrowserUpProxy- Parameters:
status- Http status- Returns:
- Assertion result
-
assertMostRecentResponseStatusCode
public AssertionResult assertMostRecentResponseStatusCode(HttpStatusClass clazz)
Description copied from interface:BrowserUpProxyAssert that the most recent response has status belonging to specified class.- Specified by:
assertMostRecentResponseStatusCodein interfaceBrowserUpProxy- Parameters:
clazz- Http status class- Returns:
- Assertion result
-
assertMostRecentResponseStatusCode
public AssertionResult assertMostRecentResponseStatusCode(java.util.regex.Pattern url, java.lang.Integer status)
Description copied from interface:BrowserUpProxyAssert that the most recent response found by url pattern has specified status.- Specified by:
assertMostRecentResponseStatusCodein interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)status- Http status- Returns:
- Assertion result
-
assertMostRecentResponseStatusCode
public AssertionResult assertMostRecentResponseStatusCode(java.util.regex.Pattern url, HttpStatusClass clazz)
Description copied from interface:BrowserUpProxyAssert that the most recent response found by url pattern has status belonging to specified class.- Specified by:
assertMostRecentResponseStatusCodein interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)clazz- Http status class- Returns:
- Assertion result
-
assertMostRecentResponseContentLengthLessThanOrEqual
public AssertionResult assertMostRecentResponseContentLengthLessThanOrEqual(java.util.regex.Pattern url, java.lang.Long max)
Description copied from interface:BrowserUpProxyAssert that content length of the most recent response found by url pattern does not exceed max value.- Specified by:
assertMostRecentResponseContentLengthLessThanOrEqualin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)max- Max length of content, inclusive- Returns:
- Assertion result
-
assertMostRecentResponseHeaderContains
public AssertionResult assertMostRecentResponseHeaderContains(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)
Description copied from interface:BrowserUpProxyAssert that if the most recent response found by url pattern has header with specified name - it's value must contain specified text.- Specified by:
assertMostRecentResponseHeaderContainsin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)name- Header namevalue- Header value- Returns:
- Assertion result
-
assertMostRecentResponseHeaderDoesNotContain
public AssertionResult assertMostRecentResponseHeaderDoesNotContain(java.util.regex.Pattern url, java.lang.String name, java.lang.String value)
Description copied from interface:BrowserUpProxyAssert that if the most recent response found by url pattern has header with specified name - it's value must not contain specified text.- Specified by:
assertMostRecentResponseHeaderDoesNotContainin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)name- Header namevalue- Header value- Returns:
- Assertion result
-
assertMostRecentResponseHeaderMatches
public AssertionResult assertMostRecentResponseHeaderMatches(java.util.regex.Pattern url, java.util.regex.Pattern name, java.util.regex.Pattern value)
Description copied from interface:BrowserUpProxyAssert that if the most recent response found by url pattern has header with name found by name pattern - it's value should match value pattern.- Specified by:
assertMostRecentResponseHeaderMatchesin interfaceBrowserUpProxy- Parameters:
url- Regular expression match of URL to find. See examplesBrowserUpProxy.findEntries(java.util.regex.Pattern)name- Regular expression match of header name to find.value- Regular expression match of header value.- Returns:
- Assertion result
-
isMitmDisabled
public boolean isMitmDisabled()
-
setUseEcc
public void setUseEcc(boolean useEcc)
-
addBrowserUpFilters
protected void addBrowserUpFilters()
Adds the basic BrowserUp-proxy filters, except for the relatively-expensive HAR capture filter.
-
addHarCaptureFilter
protected void addHarCaptureFilter()
Enables the HAR capture filter if it has not already been enabled. The filter will be added to the end of the filter chain. The HAR capture filter is relatively expensive, so this method is only called when a HAR is requested.
-
-