Developer

Conditional GET Requests

Add conditional GET requests to occasionally offline OData applications that use an online store.

The HTTP 1/1 Protocol defines a caching mechanism that allows HTTP clients to cache HTTP content (pages, media files, images, and so on). When an HTTP client requests a resource that is already cached, the server can send a 304 Not Modified response indicating that the resource has not changed. The protocol is defined as:
  1. The server sends the following HTTP headers:
    • Cache-Control specifies if the server supports HTTP caching. no-cache and/or no-store values indicate that the server does not support HTTP caching. If the Cache-Control header value is max-age=sec (where <sec> is the maximum age in seconds of the cached resource), then the server supports HTTP caching.
    • Last-Modified a timestamp indicating when the resource was modified.
    • etag the version token of the resource (generated by the server).
  2. Before the HTTP client sends a request it verifies that the specified resource exists in the cache with these headers: Cache-Control=max-age=sec, Last-Modified, and etag. It then sends the request including these headers:
    • etag the same version token sent previously by the server.
    • If-Modified-Since the same timestamp sent previously by the server in the Last-Modified header.
  3. When the server receives a request with the required headers, it checks the resource. If the resource has been:
    • Modified the server sends back the new resource with new Last-Modified and etag headers.
    • Not modified the server sends back a 304 Not Modified response.

Online store support for HTTP conditional GET

The OData Online store technical cache stores cached responses for the specified URLs, and OData responses are extended with these headers to support HTTP conditional GET:
  • Last-Modified
  • etag

    These are filled with HTTP header values sent from the server responses. When a request is scheduled/executed, the online store checks these headers. If they exist for a particular response, the online store adds If-Modified-Since and etag headers to the HTTP request based on the sotred response headers. When a response arrives, the online store checks its status code. If it is 304 Not Modified, then the online store calls the server response with the "old" cached response. If the status code is 2xx, then the online store updates the cache and calls the server response with the new content.

  • An updated flag is added to the odata response: the flag is always "true" except when the server sends back the 304 Not Modified response.