Conditional GET

Conditional GET

PCBWay

Although caching can reduce user-perceived response times, it introduces a new problem  the copy of an object residing in the cache may be stale. In other words, the object housed in the web server may have been modified since the copy was cached at the client. Fortunately, HTTP has a mechanism that allows a cache to verify that its objects are up to date. This mechanism is called the conditional GET. An HTTP request message is so-called conditional GET message if (1) the request message uses the GET method and (2) the request message includes an If-Modified-Since: header line.

To illustrate how the conditional GET operates, let’s walk through an example.

First, on behalf of a requesting browser, a proxy cache sends a request message to a web server:

GET /fruit/kiwi.gif HTTP/1.1

Host: www.exotiquecuisine.com

Second, the web server sends a response message with the requested object to the cache:

HTTP/1.1  200 OK

Date: Sat, 8 Oct 2011 15:39:29

Server: Apache/1.3.0 (Unix)

Last-Modified: Wed, 7 Sep  2011  09:23:24

Content-Type: image/gif

 

(data data data data ……………)

The cache forwards the object to the requesting browser but also caches the object locally. Importantly, the cache also stores the last-modified date along with the object. Third, one week later, another browser requests the same object via the cache, and the object is still in the cache. Since, this object may have been modified at the web server in the past week, the cache performs an up-to-date check by issuing a conditional GET. Specifically, the cache sends:

GET /fruit/kiwi.gif  HTTP/1.1

Host: www.exotiquecuisine.com

If-modified-since: Wed, 7 Sep 2011 09:23:24

Not that the value of the If-modified-since: header line is exactly equal to the value of the Last-Modified: header line that was sent by the server one week ago. This conditional GET is telling the server to send the object only if the object has been modified since the specified date. Suppose the object has not been modified since 7 Sep 2011 09:23:24. Then, fourth, the web server sends a response message to the cache:

HTTP/1.1  304 Not Modified

Date: Sat, 15 Oct 2011 15:39:29

Server: Apache/1.3.0 (Unix)

(empty entity body)

We see that in response to the conditional GET, the web server still sends a response message but does not include the requested object in the response message. Including the requested object would only waste bandwidth and increase user-perceived response time, particularly if the object is large. Note that this last response message has 304 Not Modified in the status line, which tells the cache that it can go ahead and forward its (the proxy cache’s) cached copy of the object to the requesting browser.

This ends our discussion of HTTP, the first Internet protocol (an application layer protocol) that we’ve studied in detail. We’ve seen that format of HTTP messages and the actions taken by the web client and server as these messages are sent and received. We’ve also studies a bit of the web’s application infrastructure, including caches, cookies, and back-end databases, all of which are tied in some way to the HTTP protocol.