Wednesday, January 9, 2008

Browser Cache Emulation in OpenSTA

Browser Cache Emulation in OpenSTA

In Load Runner there is option available to emulate the browser cache, there is no such facility in OpenSTA directly, but through the scripting you can emulate this cache.

First we will go through the background of HTTP cache.

HTTP caching is of the best ways to reduce roundtrips and bytes transferred. Caching provides a mechanism for a client or proxy to store HTTP responses for later use, so that requests need not cross the network.

Other than performance, another benefit of maximizing use of HTTP caching comes from the fact that bandwidth isn't free

Cache-Related Request Headers

To enhance performance, Microsoft Internet Explorer and other Web clients maintain a local cache of resources downloaded from remote Web servers.

When a resource is needed by the client, there are three possible actions:

· Send a plain HTTP request to the remote Web server asking for a resource

· Send a conditional HTTP request to the origin server asking for the resource only if it differs from the locally cached version

· Use a locally cached version of the resource, if a cached copy is available



When sending a request, the client may use one of the following headers:

Table 1. Client Cache Headers

Pragma: no-cache
The client is unwilling to accept any cached responses from caches along the route and the origin server must be contacted for a fresh copy of the resource.

If-Modified-Since: datetime
The server should return the requested resource only if the resource has been modified since the date-time provided by the client.

If-None-Match: etagvalue
The server should return the requested resource if the ETAG of the resource is different than the value provided by the client. An ETAG is a unique identifier representing a particular version of a





A client indicates that it has a cached response available for use by sending a "Conditional request" containing the headers If-Modified-Since or If-None-Match. If the server replies to a conditional request with HTTP/304 Not Modified, the client is directed to reuse its cached response. Otherwise, the server should return a new response and the client should discard its outdated cache item.





Observe two consecutive requests for an image file in the following code sessions. In the first session, no locally cached version of the file is present, so the server returns the file along with an ETAG value and the date-time of the last modification of the file. In the subsequent session, a locally cached version of the file is now available, so a conditional request is made, passing up the ETAG of the cached response as well as the Last-Modified time of the original request. Since the image has not changed since the cached version (either because the ETAG matches or the If-Modified-Since value matches the Last-Modified value) the server returns a 304 to the client to direct it to use the cached response.



Session #1

GET /images/banner.jpg HTTP/1.1Host: www.bayden.com HTTP/1.1 200 OKDate: Tue, 08 Mar 2006 00:32:46 GMTContent-Length: 6171Content-Type: image/jpegETag: "40c7f76e8d30c31:2fe20"Last-Modified: Thu, 12 Jun 2003 02:50:50 GMTSession #2

GET /images/banner.jpg HTTP/1.1If-Modified-Since: Thu, 12 Jun 2003 02:50:50 GMTIf-None-Match: "40c7f76e8d30c31:2fe20"Host: www.bayden.com HTTP/1.1 304 Not ModifiedBecause an HTTP/304 response contains only headers and no body, it crosses the network much more quickly than if the full resource had been re-downloaded. However, even an HTTP/304 requires a full roundtrip to the remote Web server; by carefully setting response headers, a Web application developer can eliminate the need to issue even conditional requests.



OpenSTA SCL Scripting



This is just background of HTTP Cache, we can conclude that HTTP cache will return the 304 HTTP code if it is from cache,

As shown below in yellow mark is responsible for the HTTP cache ,

To correlate the value just follow the very first same request in OpenSTA script . then into server header pan from right side and just correlate that value



GET URI "http://localhost/MercuryWebTours/images/banner_merctur.jpg HTTP/1.0" ON 2 & HEADER DEFAULT_HEADERS &

,WITH {"Accept: */*", &

"Referer: http://localhost/MercuryWebTours/home.html", &

"Accept-Language: en-us", &

"Cookie: "+cookie_2_1, &

"If-Modified-Since: Sun, 10 Jan 1999 23:07:04 GMT; length=22548", &

"Connection: Keep-Alive"}





To verify just run it once and check the HTTP status code it should 200 for first request but for later requests it should be 304

No comments: