type

FileWeblet

class FileWeblet : Obj, Weblet

FileWeblet is used to service an HTTP request on a File. It handles all the dirty details for cache control, compression, modification time, ETags, etc.

Default implementation uses gzip encoding if gzip is supported by the client and the file's MIME type has a "text" media type.

Current implementation supports ETags and Modification time for cache validation. It does not specify any cache control directives.

constructors

make

Constructor with file to service.

fields

extraResHeaders

Extra response headers to add for all 3xx and 2xx responses

file

The file being serviced by this FileWeblet.

methods

checkNotModified

Check if the request passed headers indicating it has cached version of the file.

checkUnderDir

Checks if the file being served is under the given directory.

etag

Compute the ETag for the file being serviced which uniquely identifies the file version.

modified

Get the modified time of the file floored to 1 second which is the most precise that HTTP can deal with.

onGet

Handle GET request for the file.

onService

Slot Details

checkNotModified

protected virtual Bool checkNotModified()

Check if the request passed headers indicating it has cached version of the file. If the file has not been modified, then service the request as 304 and return true. This method supports ETag "If-None-Match" and "If-Modified-Since" modification time.

checkUnderDir

This checkUnderDir(File dir)

Checks if the file being served is under the given directory. If it is not, a 404 response is immediately sent, short-circuiting any further attempts to serve the file.

FileWeblet(file).checkUnderDir(dir).onService

etag

virtual Str etag()

Compute the ETag for the file being serviced which uniquely identifies the file version. The default implementation is a hash of the modified time and the file size. The result of this method must conform to the ETag syntax and be wrapped in quotes.

extraResHeaders

[Str:Str]? extraResHeaders

Extra response headers to add for all 3xx and 2xx responses

file

const File file

The file being serviced by this FileWeblet.

make

new make(File file)

Constructor with file to service.

modified

virtual DateTime modified()

Get the modified time of the file floored to 1 second which is the most precise that HTTP can deal with.

onGet

virtual override Void onGet()

Handle GET request for the file.

onService

virtual override Void onService()