- Index
- »
- fan.web
- »
- FileWeblet
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.
Constructor with file to service
Extra response headers to add for all 3xx and 2xx responses
The file being serviced by this FileWeblet
Checks if the file being served is under the given directory
Handle GET request for the file
Get the modified time of the file floored to 1 second which is the most precise that HTTP can deal with
Compute the ETag for the file being serviced which uniquely identifies the file version
Check if the request passed headers indicating it has cached version of the file
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.
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
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.
[Str:Str]? : extraResHeaders
Extra response headers to add for all 3xx and 2xx responses
const File : file
The file being serviced by this FileWeblet.
new make(File file)
Constructor with file to service.
virtual DateTime modified()
Get the modified time of the file floored to 1 second which is the most precise that HTTP can deal with.
virtual Void onGet()
Handle GET request for the file.
virtual Void onService()