Demonstrates standard-compliant HTTP caching strategies to optimize web performance. This example showcases using 'HashSHA256' to generate content fingerprints, illustrating how to inspect 'WebRequest.Header' for conditional validation and use 'WebResponse.SetETag' to implement efficient 304 Not Modified status handling.
<?pas
uses System.Net, System.Crypto;
var content := 'Immutable Content v1.0';
// Using SHA256 for ETag
var etag := '"' + HashSHA256.HashData(content) + '"';
// Check if client has a matching ETag
if WebRequest.Header['If-None-Match'] = etag then begin
WebResponse.StatusCode := 304; // Not Modified
exit;
end;
WebResponse.SetETag(etag);
WebResponse.ContentType := 'text/plain';
WebResponse.ContentData := content;
?>
Immutable Content v1.0