HTTP Header Manipulation APIs
These APIs help manipulate HTTP headers to test behaviour of modified browsers or devices.
Set Http Header
Section titled “Set Http Header”Modes Browser
Sets the HTTP header for all further requests made in this browser session. If a HTTP header of given key already exists, it will be replaced.
Parameters
| Name | Type | Description |
|---|---|---|
$key | string | HTTP header name |
$value | string | HTTP header value |
Raw script
//Set the User-Agent to that sent by iPad2var $userAgent = "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X; en-us) " + "AppleWebKit/534.46 (KHTML, like Gecko) " + "Version/5.1 Mobile/9B176 Safari/7534.48.3";_setHttpHeader("User-Agent", $userAgent);Sahi Pro Classic API _setHttpHeader
Add Http Header
Section titled “Add Http Header”Modes Browser
Adds the HTTP header for all further requests made in this browser session. If a HTTP header of given key already exists, both old and new headers will be sent.
Parameters
| Name | Type | Description |
|---|---|---|
$key | string | HTTP header name |
$value | string | HTTP header value |
Sahi Pro Classic API _addHttpHeader
Remove Http Header
Section titled “Remove Http Header”Modes Browser
Removes a particular HTTP header. For example, can be used to check behaviour when user-agent is not sent
Parameters
| Name | Type | Description |
|---|---|---|
$key | string | HTTP header name |
Raw script
_removeHttpHeader("User-Agent");Sahi Pro Classic API _removeHttpHeader
Reset Http Header
Section titled “Reset Http Header”Modes Browser
If _addHttpHeader or _setHttpHeader or _removeHttpHeader had been called in this session before, calling Reset Http Header will revert it to the original behaviour, before any of those APIs were called.
Parameters
| Name | Type | Description |
|---|---|---|
$key | string | HTTP header name |
Raw script
_removeHttpHeader("User-Agent"); // remove header// do a few actions// requests will not be sending user-agent_resetHttpHeader("User-Agent"); // revert back// will send user-agent header as the browser normally does.Sahi Pro Classic API _resetHttpHeader
Map Domain To IP
Section titled “Map Domain To IP”Modes Browser
Used to map a domain to a specific IP. For example while testing, a thirdparty service may be mocked out with a server on a local IP.
If you add
Parameters
| Name | Type | Description |
|---|---|---|
$urlBase | string | url with protocol, domain and port (if present). Ex. http://dummy.domain.com/ or https://dummy.domain.com:8080/ |
$ip | string|object | IP to map url's domain to. If $ip is not specified or is null, any existing mapping for that domain will be removed. |
Raw script
_mapDomainToIP("http://www.google.com/", "127.0.0.1");Sahi Pro Classic API _mapDomainToIP
Keep-Alive
Section titled “Keep-Alive”The connection between the browser and proxy normally uses keep-alive=true. Sometimes, pages with applets or flex objects hang if keep-alive is true. In such cases, _disableKeepAlive can be used before loading the applet/flex object and then _enableKeepAlive() can be called to restore original behaviour.
Disable Keep Alive
Section titled “Disable Keep Alive”Modes Browser
Disable Keep Alive() turns off Keep-Alive between browser and proxy.
Parameters
| Name | Type | Description |
|---|---|---|
None |
Sahi Pro Classic API _disableKeepAlive
Enable Keep Alive
Section titled “Enable Keep Alive”Modes Browser
Enable Keep Alive() turns on Keep-Alive between browser and proxy.
Parameters
| Name | Type | Description |
|---|---|---|
None |
Sahi Pro Classic API _enableKeepAlive
Example:
_disableKeepAlive();_call(loadPageWithFlashWhichHangsOtherwise());_enableKeepAlive()Cookie APIs
Section titled “Cookie APIs”Get Cookie
Section titled “Get Cookie”Modes Browser
Get Cookie() gets the value of cookie with the given name for the current page.
Provide the path parameter if the cookie was assigned by the server to a specific path.
Parameters
| Name | Type | Description |
|---|---|---|
$name | string | Cookie name |
$path | stringoptional | Location for which the cookie is assigned |
Returns
string | Value of cookie with given name |
Sahi Pro Classic API _cookie
Create Cookie
Section titled “Create Cookie”Modes Browser
Parameters
| Name | Type | Description |
|---|---|---|
$name | string | Cookie name |
$value | string | Cookie value |
$days | integer | Days to expiry |
Sahi Pro Classic API _createCookie
Delete Cookie
Section titled “Delete Cookie”Modes Browser
Deletes the cookie with given name for the current page. This may or may not work. A better way may be to use the Cookie Manager
Cookie Manager” class=“headinganchor2” hideFocus=“hideFocus”>Cookie Manager
Section titled “Cookie Manager” class=“headinganchor2” hideFocus=“hideFocus”>Cookie Manager”Cookies are specific to domains. To see all cookies of a particular domain, you can navigate to http://yourdomain.com/_s_/dyn/Cookies_showAll This page will show you all cookies associated with yourdomain.com. You can choose and delete cookies from this page. This handles httpOnly cookies also.
Note that if you want to delete a cookie from www.yahoo.com, you should navigate to both http://www.yahoo.com/_s_/dyn/Cookies_showAll and http://yahoo.com/_s_/dyn/Cookies_showAll and delete the relevant cookie.
Parameters
| Name | Type | Description |
|---|---|---|
$name | string | Cookie name |
Sahi Pro Classic API _deleteCookie

