HTTP Header Manipulation APIs

abstract These APIs help manipulate HTTP headers to test behaviour of modified browsers or devices.

_setHttpHeader

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
4.0NANANANA

Available for modes: Browser

_setHttpHeader($key, $value)

Arguments
$keystring HTTP header name
$valuestring HTTP header value

Returns
null

Sahi Pro Flowcharts Action :Set Http Header

Details

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.
//Set the User-Agent to that sent by iPad2
var $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);


_addHttpHeader

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
4.0NANANANA

Available for modes: Browser

_addHttpHeader($key, $value)

Arguments
$keystring HTTP header name
$valuestring HTTP header value

Returns
null

Sahi Pro Flowcharts Action :Add Http Header

Details

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.
warning Only specific HTTP headers can be sent in multiples. Read the HTTP specification and understand the behaviour before you use this API.


_removeHttpHeader

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
4.0NANANANA

Available for modes: Browser

_removeHttpHeader($key)

Arguments
$keystring HTTP header name

Returns
null

Sahi Pro Flowcharts Action :Remove Http Header

Details

Removes a particular HTTP header. For example, can be used to check behaviour when user-agent is not sent
_removeHttpHeader("User-Agent");


_resetHttpHeader

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
4.0NANANANA

Available for modes: Browser

_resetHttpHeader($key)

Arguments
$keystring HTTP header name

Returns
null

Sahi Pro Flowcharts Action :Reset Http Header

Details

If _addHttpHeader or _setHttpHeader or _removeHttpHeader had been called in this session before, calling _resetHttpHeader will revert it to the original behaviour, before any of those APIs were called.
_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.


_mapDomainToIP

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
5.1.0NANANANA

Available for modes: Browser

_mapDomainToIP($urlBase, $ip)

Arguments
$urlBasestring url with protocol, domain and port (if present). Ex. http://dummy.domain.com/ or https://dummy.domain.com:8080/
$ipstring|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.

Returns
null

Sahi Pro Flowcharts Action :Map Domain To IP

Details

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
_mapDomainToIP("http://www.google.com/", "127.0.0.1");
at the start of the script, all requests to http://www.google.com will be responded to by your localhost server.
info NOTE: The port and protocols will not be changed, only the IP will be mapped to this domain.
_mapDomainToIP("http://www.google.com/"); // remove any previously set mapping.
// All requests to http://www.google.com will now go to http://www.google.com correctly.


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.

_disableKeepAlive

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
3.5NANANANA

Available for modes: Browser

_disableKeepAlive()

Arguments
None

Returns
null

Sahi Pro Flowcharts Action :Disable Keep Alive

Details

_disableKeepAlive() turns off Keep-Alive between browser and proxy.


_enableKeepAlive

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
3.5NANANANA

Available for modes: Browser

_enableKeepAlive()

Arguments
None

Returns
null

Sahi Pro Flowcharts Action :Enable Keep Alive

Details

_enableKeepAlive() turns on Keep-Alive between browser and proxy.


Example:
_disableKeepAlive();
_call(loadPageWithFlashWhichHangsOtherwise());
_enableKeepAlive()


Cookie APIs

_cookie

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
3.5NANANANA

Available for modes: Browser

_cookie($name[, $path])

Arguments
$namestring Cookie name
$pathstring optionalLocation for which the cookie is assigned

Returns
stringValue of cookie with given name

Sahi Pro Flowcharts Action :Get Cookie

Details

infoNOTE: $path was added Since Sahi Pro: 9.0.0. For old document Refer here
_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.


_createCookie

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
3.5NANANANA

Available for modes: Browser

_createCookie($name, $value, $days)

Arguments
$namestring Cookie name
$valuestring Cookie value
$daysinteger Days to expiry

Returns
null

Sahi Pro Flowcharts Action :Create Cookie

Details

warningWhile possible to create a cookie, there is no real reason to create one during automation.


_deleteCookie

Since: Sahi ProDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
3.5NANANANA

Available for modes: Browser

_deleteCookie($name)

Arguments
$namestring Cookie name

Returns
null

Sahi Pro Flowcharts Action :Delete Cookie

Details

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

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.