|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface HttpClient
The API that makes HTTP requests for BrowserMob scripts. This API is used directly by VU scritps and indirectly by RBU scripts (browser requests are proxied through here). In either case, requests to this API are logged in the transaction results, with timings for time-to-first-byte, DNS lookup, time-to-last-byte, etc captured.
In addition to the basic GET/POST HTTP actions, this API provides many useful utilities to extend/modify the normal script or browser behavior. For example:remapHost(java.lang.String, java.lang.String) - Useful for simulating entries in your /etc/hosts file.addRequestInterceptor(HttpRequestInterceptor) - Allows your scripts to modify the behavior of all request in a single place.autoBasicAuthorization(java.lang.String, java.lang.String, java.lang.String) - If your site is protected by BASIC authentication, use this.rewriteUrl(java.lang.String, java.lang.String) - Uses regular expressions to rewrite a URL before the request is made.blacklistRequests(java.lang.String, int) and whitelistRequests(java.lang.String[], int) - For when you don't want certain requests to even be made.
| Method Summary | |
|---|---|
void |
addRequestInterceptor(HttpRequestInterceptor i)
Registers a hook that will be called upon every single HTTP request. |
void |
addResponseInterceptor(HttpResponseInterceptor i)
Registers a hook that will be called upon every single HTTP response. |
void |
autoBasicAuthorization(java.lang.String domain,
java.lang.String username,
java.lang.String password)
Forces all requests to the specific domain ("example.com") or host ("www.example.com) to have the proper header necessary to automatically pass any BASIC authentication challenge (ie: the Authorization header) with the supplied username and password. |
void |
blacklistRequests(java.lang.String pattern,
int responseCode)
Instructs BrowserMob to blacklist any HTTP request that matches the supplied regular expression pattern, automatically registering the supplied response code as the response without actually making the call. |
void |
clearCookies()
Remove all cookies. |
void |
clearDNSCache()
Flushes the DNS cache used by this http client |
void |
createCookie(java.lang.String name,
java.lang.String value,
java.lang.String domain)
Create a new cookie. |
void |
createCookie(java.lang.String name,
java.lang.String value,
java.lang.String domain,
java.lang.String path)
Create a new cookie. |
HttpResponse |
get(java.lang.String url)
Issues an HTTP GET without any content verification. |
HttpResponse |
get(java.lang.String url,
int expectedStatusCode)
Issues an HTTP GET without any content verification but with a status code check. |
HttpResponse |
get(java.lang.String url,
int expectedStatusCode,
java.lang.String expectedLocation)
Issues an HTTP GET without any content verification but with a status code check and, in case of a redirection, a location redirect check. |
HttpResponse |
get(java.lang.String url,
java.lang.String verificationText)
Issues an HTTP GET with content verification. |
HttpResponse |
get(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode)
Issues an HTTP GET with content verification and automatic status code checking. |
HttpResponse |
get(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode,
java.lang.String expectedLocation)
Issues an HTTP GET with content verification and automatic status code checking. |
Cookie |
getCookie(java.lang.String name)
Retrieve a cookie by name. |
Cookie |
getCookie(java.lang.String name,
java.lang.String domain)
Retrieve a cookie by name. |
Cookie |
getCookie(java.lang.String name,
java.lang.String domain,
java.lang.String path)
Retrieve a cookie by name. |
HttpGetRequest |
newGet(java.lang.String url)
Creates a new GET request that can be further modified before finally executed. |
HttpPostRequest |
newPost(java.lang.String url)
Creates a new POST request that can be further modified before finally executed. |
HttpResponse |
post(java.lang.String url)
Issues an HTTP POST without any content verification. |
HttpResponse |
post(java.lang.String url,
int expectedStatusCode)
Issues an HTTP POST with content verification and automatic status code checking. |
HttpResponse |
post(java.lang.String url,
int expectedStatusCode,
java.lang.String expectedLocation)
Issues an HTTP POST with content verification and automatic status code checking. |
HttpResponse |
post(java.lang.String url,
java.lang.String verificationText)
Issues an HTTP POST with content verification. |
HttpResponse |
post(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode,
NativeObject paramsNO)
Issues an HTTP POST with content verification and automatic status code checking. |
HttpResponse |
post(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode,
java.lang.String expectedLocation,
NativeObject paramsNO)
Issues an HTTP POST with content verification and automatic status code checking. |
HttpResponse |
post(java.lang.String url,
java.lang.String verificationText,
NativeObject paramsNO)
Issues an HTTP POST with content verification. |
void |
remapHost(java.lang.String source,
java.lang.String target)
Provides functionality similar to editing your "hosts file" on your local computer. |
void |
rewriteUrl(java.lang.String match,
java.lang.String replace)
Tells the browser to rewrite any URL it encounters using the provided regular expression and replacement string. |
void |
setConnectionTimeout(int connectionTimeout)
Sets the timeout for the connection to be established. |
void |
setDNSCacheTimeout(int timeout)
Sets the TTL for objects in the DNS cache in seconds. |
void |
setFollowRedirects(boolean followRedirects)
Tells the HttpClient whether redirects (300 status codes) should automatically be followed. |
void |
setRequestTimeout(int requestTimeout)
Sets the request timeout for all subsequent HTTP requests. |
void |
setRetryCount(int count)
Set the automatic retry count for HTTP requests (for VUs and RBUs alike). |
void |
setSocketOperationTimeout(int socketOperationTimeout)
Sets the timeout for a socket operation, such as reading a byte from the HTTP stream (SO_TIMEOUT). |
void |
whitelistRequests(java.lang.String[] patterns,
int responseCode)
Instructs BrowserMob to whitelist any HTTP request that matches the supplied regular expression patterns, automatically registering the supplied response code as the response for any request not in the set of whitelists. |
| Method Detail |
|---|
void setRetryCount(int count)
count - the number of times to retry an HTTP request (0 by default)
void remapHost(java.lang.String source,
java.lang.String target)
source - the source host to re-map from (ie: www.example.com)target - the target host to re-map to (ie: new.example.com)void addRequestInterceptor(HttpRequestInterceptor i)
c.addRequestInterceptor(function(req) {
// do something to the request
});
The req argument in your callback function has it's own set of functions that you can use to
add/remove/edit headers and get the requesting URL. Consult the API
documentation for the underlying library that BrowserMob uses (Apache HTTP Client) to see all the functions
available to you.
i - the javascript function, in the form of function(req) { ... }void addResponseInterceptor(HttpResponseInterceptor i)
c.addRequestInterceptor(function(res) {
// do something to the response
});
The res argument in your callback function has it's own set of functions that you can use to
read response headers and the status code. Consult the API
documentation for the underlying library that BrowserMob uses (Apache HTTP Client) to see all the functions
available to you.
i - the javascript function, in the form of function(res) { ... }
void autoBasicAuthorization(java.lang.String domain,
java.lang.String username,
java.lang.String password)
domain - the domain or host to auto authenticateusername - the username to login withpassword - the password to login with
void createCookie(java.lang.String name,
java.lang.String value,
java.lang.String domain)
name - value - domain -
void createCookie(java.lang.String name,
java.lang.String value,
java.lang.String domain,
java.lang.String path)
name - value - domain - path - void clearCookies()
Cookie getCookie(java.lang.String name)
name - the name of the cookie
Cookie getCookie(java.lang.String name,
java.lang.String domain)
name - the name of the cookiedomain - the domain for which the cookie is valid
Cookie getCookie(java.lang.String name,
java.lang.String domain,
java.lang.String path)
name - the name of the cookiedomain - the domain for which the cookie is validpath - the subset of URLs on the origin server to which this cookie applies
void rewriteUrl(java.lang.String match,
java.lang.String replace)
match - the regular expression string to match against. You can use regex symbols such as ".", "\d", "\W",
"[...]", etc.replace - the plain text string to replace any matching subsection of a URL handled by the browser.
void blacklistRequests(java.lang.String pattern,
int responseCode)
c.blacklistRequests("http://www\\.google-analytics\\.com/.*", 200);
pattern - the regular expression string to match against. You can use regex symbols such as ".", "\d",
"\W", "[...]", etc.responseCode - the HTTP response code to immediately "return" instead of making the actual HTTP request.
void whitelistRequests(java.lang.String[] patterns,
int responseCode)
c.whitelistRequests(["http://www\\.example\\.com/.*", "http://images\\.example.com\\.com/.*"], 200);
patterns - the array regular expression string to match against. You can use regex symbols such as ".", "\d",
"\W", "[...]", etc.responseCode - the HTTP response code to immediately "return" instead of making the actual HTTP request.HttpResponse get(java.lang.String url)
url - the URL to make an HTTP GET request to.
HttpResponse get(java.lang.String url,
int expectedStatusCode)
url - the URL to make an HTTP GET request to.expectedStatusCode - the expected status code
HttpResponse get(java.lang.String url,
int expectedStatusCode,
java.lang.String expectedLocation)
url - the URL to make an HTTP GET request to.expectedStatusCode - the expected status codeexpectedLocation - the expected redirect location
HttpResponse get(java.lang.String url,
java.lang.String verificationText)
HttpResponse object. If null is passed in to the verification text, then no content
verification is done.
url - the URL to make an HTTP GET request to.verificationText - the text to check against the returned content.
HttpResponse get(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode)
HttpResponse object. If null is passed in to the verification text, then no
content verification is done.
url - the URL to make an HTTP GET request to.verificationText - the text to check against the returned content.expectedStatusCode - the expected status code
HttpResponse get(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode,
java.lang.String expectedLocation)
HttpResponse object. If null is passed in to the verification text, then no
content verification is done.
url - the URL to make an HTTP GET request to.verificationText - the text to check against the returned content.expectedStatusCode - the expected status codeexpectedLocation - the expected redirect location
HttpResponse post(java.lang.String url)
url - the URL to make an HTTP POST request to.
HttpResponse post(java.lang.String url,
int expectedStatusCode)
url - the URL to make an HTTP POST request to.expectedStatusCode - the expected status code
HttpResponse post(java.lang.String url,
int expectedStatusCode,
java.lang.String expectedLocation)
url - the URL to make an HTTP POST request to.expectedStatusCode - the expected status codeexpectedLocation - the expected redirect location
HttpResponse post(java.lang.String url,
java.lang.String verificationText)
HttpResponse object. If null is passed in to the verification text, then no content
verification is done.
url - the URL to make an HTTP POST request to.verificationText - the text to check against the returned content.
HttpResponse post(java.lang.String url,
java.lang.String verificationText,
NativeObject paramsNO)
HttpResponse object. If null is passed in to the verification text, then no content
verification is done.
A set of HTTP parameters that are supplied in the POST data can be specified with the third argument. While the
type is documented "NativeObject", this really just means that the argument can be some sort of JavaScript
key/value pair. For example, a call might look like the following:
c.post("http://example.com", null, {
param_one: 'some value',
param_two: ['foo', 'bar']
});
url - the URL to make an HTTP POST request to.verificationText - the text to check against the returned content.paramsNO - the JavaScript map of parameters used when issuing an HTTP POST.
HttpResponse post(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode,
NativeObject paramsNO)
HttpResponse object. If null is passed in to the verification text, then no
content verification is done.
A set of HTTP parameters that are supplied in the POST data can be specified with the third argument. While the
type is documented "NativeObject", this really just means that the argument can be some sort of JavaScript
key/value pair. For example, a call might look like the following:
c.post("http://example.com", null, {
param_one: 'some value',
param_two: ['foo', 'bar']
});
url - the URL to make an HTTP POST request to.verificationText - the text to check against the returned content.expectedStatusCode - the expected status codeparamsNO - the JavaScript map of parameters used when issuing an HTTP POST.
HttpResponse post(java.lang.String url,
java.lang.String verificationText,
int expectedStatusCode,
java.lang.String expectedLocation,
NativeObject paramsNO)
HttpResponse object. If null is passed in to the verification text, then no
content verification is done.
A set of HTTP parameters that are supplied in the POST data can be specified with the third argument. While the
type is documented "NativeObject", this really just means that the argument can be some sort of JavaScript
key/value pair. For example, a call might look like the following:
c.post("http://example.com", null, {
param_one: 'some value',
param_two: ['foo', 'bar']
});
url - the URL to make an HTTP POST request to.verificationText - the text to check against the returned content.expectedStatusCode - the expected status codeexpectedLocation - the expected redirect locationparamsNO - the JavaScript map of parameters used when issuing an HTTP POST.
void setFollowRedirects(boolean followRedirects)
followRedirects - true for redirects to be followed.void setRequestTimeout(int requestTimeout)
requestTimeout - the timeout value, in milliseconds, to use.void setSocketOperationTimeout(int socketOperationTimeout)
socketOperationTimeout - the timeout value, in milliseconds, to use.void setConnectionTimeout(int connectionTimeout)
connectionTimeout - the timeout value, in milliseconds, to use.HttpGetRequest newGet(java.lang.String url)
url - the URL to make an HTTP GET request to.
HttpPostRequest newPost(java.lang.String url)
url - the URL to make an HTTP POST request to.
void clearDNSCache()
void setDNSCacheTimeout(int timeout)
timeout - timeout in seconds
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||