Package com.browserup.bup
Interface BrowserUpProxy
-
- All Known Implementing Classes:
BrowserUpProxyServer
public interface BrowserUpProxy
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidabort()Likestop(), shuts down the proxy server and no longer accepts incoming connections, but does not wait for any existing network traffic to cease.voidaddFirstHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)Adds a new filter factory (request/response interceptor) to the beginning of the HttpFilters chain.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.voidaddLastHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)Adds a new filter factory (request/response interceptor) to the end of the HttpFilters chain.voidaddRequestFilter(RequestFilter filter)Adds a new RequestFilter that can be used to examine and manipulate the request before sending it to the server.voidaddResponseFilter(ResponseFilter filter)Adds a new ResponseFilter that can be used to examine and manipulate the response before sending it to the client.voidaddWhitelistPattern(java.lang.String urlPattern)Adds a URL-matching regular expression to an existing whitelist.AssertionResultassertMostRecentUrlResponseTimeWithin(java.util.regex.Pattern url, long time)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 urlPattern, int statusCode)Adds a URL-matching regular expression to the blacklist.voidblacklistRequests(java.lang.String urlPattern, int statusCode, java.lang.String httpMethodPattern)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.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 withaddHeader(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.HargetHar()Retrieves the 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.booleanisStarted()Returns true if the proxy is started and listening for connections, otherwise false.booleanisWhitelistEnabled()Returns true if the whitelist is enabled, otherwise false.HarnewHar()Starts a new HAR file with the default page name (seenewPage().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 withaddHeader(String name, String value).voidremoveHeader(java.lang.String name)Removes a header previously added withaddHeader(String name, String value).voidremoveRewriteRule(java.lang.String urlPattern)Removes an existing rewrite rule whose urlPattern matches the specified pattern.voidrewriteUrl(java.lang.String urlPattern, java.lang.String replacementExpression)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.voidsetConnectTimeout(int connectionTimeout, 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> captureTypes)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)Maximum amount of time to allow a connection to remain idle.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.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.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.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.util.Collection<java.lang.String> urlPatterns, int statusCode)Whitelists URLs matching the specified regular expression patterns.
-
-
-
Method Detail
-
start
void start()
Starts 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).- Throws:
java.lang.IllegalStateException- if the proxy has already been started
-
start
void start(int port)
Starts the proxy on the specified port. The proxy will bind the listener to the wildcard address (0:0:0:0 - all network interfaces).- Parameters:
port- port to listen on- Throws:
java.lang.IllegalStateException- if the proxy has already been started
-
start
void start(int port, java.net.InetAddress bindAddress)Starts 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.- 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.- Throws:
java.lang.IllegalStateException- if the proxy has already been started
-
start
void start(int port, java.net.InetAddress clientBindAddress, java.net.InetAddress serverBindAddress)Starts 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.- 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- Throws:
java.lang.IllegalStateException- if the proxy has already been started
-
isStarted
boolean isStarted()
Returns true if the proxy is started and listening for connections, otherwise false.- Returns:
- is proxy started
-
stop
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. If the proxy was previously stopped or aborted, this method has no effect.- Throws:
java.lang.IllegalStateException- if the proxy has not been started.
-
abort
void abort()
Likestop(), 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.- Throws:
java.lang.IllegalStateException- if the proxy has not been started
-
getClientBindAddress
java.net.InetAddress getClientBindAddress()
Returns the address of the network interface on which the proxy is listening for client connections.- Returns:
- the client bind address, or null if the proxy has not been started
-
getPort
int getPort()
Returns the actual port on which the proxy is listening for client connections.- Returns:
- port
- Throws:
java.lang.IllegalStateException- if the proxy has not been started
-
getServerBindAddress
java.net.InetAddress getServerBindAddress()
Returns 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.- Returns:
- server bind address if one has been set, otherwise null
-
getHar
Har getHar()
Retrieves the current HAR.- Returns:
- current HAR, or null if HAR capture is not enabled
-
newHar
Har newHar()
Starts a new HAR file with the default page name (seenewPage(). Enables HAR capture if it was not previously enabled.- Returns:
- existing HAR file, or null if none exists or HAR capture was disabled
-
newHar
Har newHar(java.lang.String initialPageRef)
Starts a new HAR file with the specified initialPageRef as the page name and page title. Enables HAR capture if it was not previously enabled.- 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
Har newHar(java.lang.String initialPageRef, java.lang.String initialPageTitle)
Starts a new HAR file with the specified page name and page title. Enables HAR capture if it was not previously enabled.- 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
void setHarCaptureTypes(java.util.Set<CaptureType> captureTypes)
Sets 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 vianewHar()ornewHar(String)to begin capturing any request and response contents.- Parameters:
captureTypes- HAR data types to capture
-
setHarCaptureTypes
void setHarCaptureTypes(CaptureType... captureTypes)
Sets 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 vianewHar()ornewHar(String)to begin capturing any request and response contents.- Parameters:
captureTypes- HAR data types to capture
-
getHarCaptureTypes
java.util.EnumSet<CaptureType> getHarCaptureTypes()
- 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
void enableHarCaptureTypes(java.util.Set<CaptureType> captureTypes)
Enables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Parameters:
captureTypes- capture types to enable
-
enableHarCaptureTypes
void enableHarCaptureTypes(CaptureType... captureTypes)
Enables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Parameters:
captureTypes- capture types to enable
-
disableHarCaptureTypes
void disableHarCaptureTypes(java.util.Set<CaptureType> captureTypes)
Disables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Parameters:
captureTypes- capture types to disable
-
disableHarCaptureTypes
void disableHarCaptureTypes(CaptureType... captureTypes)
Disables the specified HAR capture types. Does not replace or disable any other capture types that may already be enabled.- Parameters:
captureTypes- capture types to disable
-
newPage
Har newPage()
Starts a new HAR page using the default page naming convention. The default page naming convention is "Page #", where "#" resets to 1 every timenewHar()ornewHar(String)is called, and increments on every subsequent call tonewPage()ornewHar(String). Populates theHarPageTiming.onLoadvalue based on the amount of time the current page has been captured.- Returns:
- the HAR as it existed immediately after ending the current page
- Throws:
java.lang.IllegalStateException- if HAR capture has not been enabled vianewHar()ornewHar(String)
-
newPage
Har newPage(java.lang.String pageRef)
Starts 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.- Parameters:
pageRef- name of the new page- Returns:
- the HAR as it existed immediately after ending the current page
- Throws:
java.lang.IllegalStateException- if HAR capture has not been enabled vianewHar()ornewHar(String)
-
newPage
Har newPage(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. Populates theHarPageTiming.onLoadvalue based on the amount of time the current page has been captured.- Parameters:
pageRef- name of the new pagepageTitle- title of the new page- Returns:
- the HAR as it existed immediately after ending the current page
- Throws:
java.lang.IllegalStateException- if HAR capture has not been enabled vianewHar()ornewHar(String)
-
endHar
Har endHar()
Stops capturing traffic in the HAR. Populates theHarPageTiming.onLoadvalue for the current page based on the amount of time it has been captured.- Returns:
- the existing HAR
-
setReadBandwidthLimit
void setReadBandwidthLimit(long bytesPerSecond)
Sets the maximum bandwidth to consume when reading server responses.- Parameters:
bytesPerSecond- maximum bandwidth, in bytes per second
-
getReadBandwidthLimit
long getReadBandwidthLimit()
Returns the current bandwidth limit for reading, in bytes per second.- Returns:
- ReadBandwidthLimit
-
setWriteBandwidthLimit
void setWriteBandwidthLimit(long bytesPerSecond)
Sets the maximum bandwidth to consume when sending requests to servers.- Parameters:
bytesPerSecond- maximum bandwidth, in bytes per second
-
getWriteBandwidthLimit
long getWriteBandwidthLimit()
Returns the current bandwidth limit for writing, in bytes per second.- Returns:
- WriteBandwidthLimit
-
setLatency
void setLatency(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.- Parameters:
latency- minimum latency, or 0 for no minimumtimeUnit- TimeUnit for the latency
-
setConnectTimeout
void setConnectTimeout(int connectionTimeout, java.util.concurrent.TimeUnit timeUnit)Maximum 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.- Parameters:
connectionTimeout- maximum time to wait to establish a connection to a server, or 0 to wait indefinitelytimeUnit- TimeUnit for the connectionTimeout
-
setIdleConnectionTimeout
void setIdleConnectionTimeout(int idleConnectionTimeout, java.util.concurrent.TimeUnit timeUnit)Maximum amount of time to allow a connection to remain idle. A connection becomes idle when it has not received data from a server within the the specified timeout. 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 60 seconds.- Parameters:
idleConnectionTimeout- maximum time to allow a connection to remain idle, or 0 to wait indefinitely.timeUnit- TimeUnit for the idleConnectionTimeout
-
setRequestTimeout
void setRequestTimeout(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. 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).- Parameters:
requestTimeout- maximum time to wait for an HTTP response, or 0 to wait indefinitelytimeUnit- TimeUnit for the requestTimeout
-
autoAuthorization
void autoAuthorization(java.lang.String domain, java.lang.String username, java.lang.String password, AuthType authType)Enables automatic authorization for the specified domain and auth type. Every request sent to the specified domain will contain the specified authorization information.- Parameters:
domain- domain automatically send authorization information tousername- authorization usernamepassword- authorization passwordauthType- authorization type
-
stopAutoAuthorization
void stopAutoAuthorization(java.lang.String domain)
Stops automatic authorization for the specified domain.- Parameters:
domain- domain to stop automatically sending authorization information to
-
chainedProxyAuthorization
void chainedProxyAuthorization(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). Currently, onlyAuthType.BASICauthentication is supported.- 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)
-
rewriteUrl
void rewriteUrl(java.lang.String urlPattern, java.lang.String replacementExpression)Adds 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 (usegetHostNameResolver()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- Parameters:
urlPattern- URL-matching regular expressionreplacementExpression- an expression, which may optionally contain capture groups, which will replace any URL which matches urlPattern
-
rewriteUrls
void rewriteUrls(java.util.Map<java.lang.String,java.lang.String> rewriteRules)
Replaces existing rewrite rules with the specified patterns and replacement expressions. The rules will be applied in the order specified by the Map's iterator. SeerewriteUrl(String, String)for details on the format of the rewrite rules.- Parameters:
rewriteRules-Map<urlPattern, replacementExpression>
-
getRewriteRules
java.util.Map<java.lang.String,java.lang.String> getRewriteRules()
Returns 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.- Returns:
Map<URL-matching regex, replacement expression>
-
removeRewriteRule
void removeRewriteRule(java.lang.String urlPattern)
Removes an existing rewrite rule whose urlPattern matches the specified pattern.- Parameters:
urlPattern- rewrite rule pattern to remove
-
clearRewriteRules
void clearRewriteRules()
Clears all existing rewrite rules.
-
blacklistRequests
void blacklistRequests(java.lang.String urlPattern, int statusCode)Adds 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/.*".- Parameters:
urlPattern- URL-matching regular expression to blackliststatusCode- HTTP status code to return
-
blacklistRequests
void blacklistRequests(java.lang.String urlPattern, int statusCode, java.lang.String httpMethodPattern)Adds 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. SeeblacklistRequests(String, int)for details on the URL the urlPattern will match.- Parameters:
urlPattern- URL-matching regular expression to blackliststatusCode- HTTP status code to returnhttpMethodPattern- regular expression matching a request's HTTP method
-
setBlacklist
void setBlacklist(java.util.Collection<BlacklistEntry> blacklist)
Replaces any existing blacklist with the specified blacklist. URLs will be evaluated against the blacklist in the order specified by the Collection's iterator.- Parameters:
blacklist- new blacklist entries
-
getBlacklist
java.util.Collection<BlacklistEntry> getBlacklist()
Returns 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.- Returns:
- blacklist entries, or an empty collection if none exist
-
clearBlacklist
void clearBlacklist()
Clears any existing blacklist.
-
whitelistRequests
void whitelistRequests(java.util.Collection<java.lang.String> urlPatterns, int statusCode)Whitelists 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.- 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
void addWhitelistPattern(java.lang.String urlPattern)
Adds a URL-matching regular expression to an existing whitelist.- Parameters:
urlPattern- URL-matching regular expressions to whitelist- Throws:
java.lang.IllegalStateException- if the whitelist is not enabled
-
enableEmptyWhitelist
void enableEmptyWhitelist(int statusCode)
Enables the whitelist, but with no matching URLs. All requests will generated the specified HTTP statusCode.- Parameters:
statusCode- HTTP status code to return to clients on all requests
-
disableWhitelist
void disableWhitelist()
Clears any existing whitelist and disables whitelisting.
-
getWhitelistUrls
java.util.Collection<java.lang.String> getWhitelistUrls()
Returns 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.- Returns:
- whitelist currently in effect, or an empty collection if the whitelist is disabled or empty
-
getWhitelistStatusCode
int getWhitelistStatusCode()
Returns the status code returned for all URLs that do not match the whitelist. If the whitelist is not currently enabled, returns -1.- Returns:
- HTTP status code returned for non-whitelisted URLs, or -1 if the whitelist is disabled.
-
isWhitelistEnabled
boolean isWhitelistEnabled()
Returns true if the whitelist is enabled, otherwise false.- Returns:
- is WhitelistEnabled
-
addHeaders
void addHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Adds the specified HTTP headers to every request. Replaces any existing additional headers with the specified headers.- Parameters:
headers-Map<header name, header value>to append to every request.
-
addHeader
void addHeader(java.lang.String name, java.lang.String value)Adds a new HTTP header to every request. If the header already exists on the request, it will be replaced with the specified header.- Parameters:
name- name of the header to addvalue- new header's value
-
removeHeader
void removeHeader(java.lang.String name)
Removes a header previously added withaddHeader(String name, String value).- Parameters:
name- previously-added header's name
-
removeAllHeaders
void removeAllHeaders()
Removes all headers previously added withaddHeader(String name, String value).
-
getAllHeaders
java.util.Map<java.lang.String,java.lang.String> getAllHeaders()
Returns all headers previously added withaddHeader(String name, String value).- Returns:
Map<header name, header value>
-
setHostNameResolver
void setHostNameResolver(AdvancedHostResolver resolver)
Sets the resolver that will be used to look up host names. To chain multiple resolvers, wrap a list of resolvers in aChainedHostResolver.- Parameters:
resolver- host name resolver
-
getHostNameResolver
AdvancedHostResolver getHostNameResolver()
Returns the current host name resolver.- Returns:
- current host name resolver
-
waitForQuiescence
boolean waitForQuiescence(long quietPeriod, long timeout, java.util.concurrent.TimeUnit timeUnit)Waits 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.- 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
void setChainedProxy(java.net.InetSocketAddress chainedProxyAddress)
Instructs this proxy to route traffic through an upstream proxy. Note: A chained proxy must be set before the proxy is started, though it can be changed after the proxy is started.- Parameters:
chainedProxyAddress- address of the upstream proxy
-
getChainedProxy
java.net.InetSocketAddress getChainedProxy()
Returns the address and port of the upstream proxy.- Returns:
- address and port of the upstream proxy, or null of there is none.
-
addFirstHttpFilterFactory
void addFirstHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
Adds 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.- Parameters:
filterFactory- factory to generate HttpFilters
-
addLastHttpFilterFactory
void addLastHttpFilterFactory(org.littleshoot.proxy.HttpFiltersSource filterFactory)
Adds 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.- Parameters:
filterFactory- factory to generate HttpFilters
-
addResponseFilter
void addResponseFilter(ResponseFilter filter)
Adds a new ResponseFilter that can be used to examine and manipulate the response before sending it to the client.- Parameters:
filter- filter instance
-
addRequestFilter
void addRequestFilter(RequestFilter filter)
Adds a new RequestFilter that can be used to examine and manipulate the request before sending it to the server.- Parameters:
filter- filter instance
-
setMitmDisabled
void setMitmDisabled(boolean mitmDisabled)
Completely 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.- Parameters:
mitmDisabled- when true, MITM capture will be disabled- Throws:
java.lang.IllegalStateException- if the proxy is already started
-
setMitmManager
void setMitmManager(org.littleshoot.proxy.MitmManager mitmManager)
Sets 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.- Parameters:
mitmManager- MITM manager to use
-
setTrustAllServers
void setTrustAllServers(boolean trustAllServers)
Disables 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.- Parameters:
trustAllServers- when true, disables upstream server certificate verification
-
setTrustSource
void setTrustSource(com.browserup.bup.mitm.TrustSource trustSource)
Sets theTrustSourcethat contains trusted root certificate authorities that will be used to validate upstream servers' certificates. When null, disables certificate validation (see warning atsetTrustAllServers(boolean)).- Parameters:
trustSource- TrustSource containing root CAs, or null to disable upstream server validation
-
findMostRecentEntry
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.- 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
java.util.Collection<HarEntry> findEntries(java.util.regex.Pattern url)
Search the entire log for entries whose request URL matches the givenurl.- 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.
-
assertMostRecentUrlResponseTimeWithin
AssertionResult assertMostRecentUrlResponseTimeWithin(java.util.regex.Pattern url, long time)
-
-