Creates an instance of this type that serves files from pathOfDirectoryToServe
.
An instance of this type serves files by appending all or part of an HTTP request path to pathOfDirectoryToServe
and streaming the bytes
of that file as a response.
Instances of this type are piped from a route that MUST contain the match-all route pattern (*
). For example, consider the following:
router
.route("/site/*")
.pipe(new HTTPFileController("build/web"));
In the above, GET /site/index.html
would respond with the contents of the file build/web/index.html
, relative to the project directory.
If pathOfDirectoryToServe
contains a leading slash, it is an absolute path. Otherwise, it is relative to the current working directory
of the running application.
The content type of the response is determined by the file extension of the served file. There are many built-in extension-to-content-type mappings and you may
add more with setContentTypeForExtension. Unknown file extension will result in application/octet-stream
content-type responses.
The contents of a file will be compressed with 'gzip' if the request allows for it and the content-type of the file can be compressed according to HTTPCodecRepository.
Note that the 'Last-Modified' header is always applied to a response served from this instance.
Source
HTTPFileController(String pathOfDirectoryToServe) : _servingDirectory = new Uri.directory(pathOfDirectoryToServe);