dj

The Daraja HTTP Framework is a free open source library for Object Pascal (Free Pascal 3.0.4, Delphi 2009+), based on the stand-alone HTTP server component in Internet Direct (Indy). The 1.2.10 release contains a new method in the TdjWebComponent class, OnGetLastModified.

Caching support

WebComponents may override the new OnGetLastModified method to indicate the last change date of the resource. If a web client sends a HTTP request with a If-Modified-Since request header, the Daraja framework will check to see if the resource has been modified since the last time the client accessed the resource. If the answer is yes, the server returns a new copy of the resource to the client, if no, the server responds with a 304 Not Modified and the browser can retrieve the content from its cache.

Example

The OnGetLastModified code in the example below returns the current local date without time:

function TCachedGetComponent.OnGetLastModified(Request: 
           TdjRequest): TDateTime;
begin
  Result := Date;
end;

This indicates that the resource has been last updated at 00:00 of the day. A client may use a cached copy of the resource, and will receive new resource content on the next day.

Unit test

The DUnit / FPCUnit test suite includes a test for the new feature in unit ConfigAPITests.

References

This feature is based on original code in TIdHTTPResponseInfo.SmartServeFile.

See also: https://www.keycdn.com/support/304-not-modified

More information
– GitHub: https://github.com/michaelJustin/daraja-framework
– API documentation: https://michaeljustin.github.io/daraja-framework/
– Resources: https://www.habarisoft.com/daraja_framework.html
– Wiki: https://github.com/michaelJustin/daraja-framework/wiki

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s