Did you know ... | Search Documentation: |
http_files.pl -- Serve plain files from a hierarchy |
Although the SWI-Prolog Web Server is intended to serve documents that
are computed dynamically, serving plain files is sometimes necessary.
This small module combines the functionality of http_reply_file/3 and
http_reply_dirindex/3 to act as a simple web-server. Such a server can
be created using the following code sample, which starts a server at
port 8080 that serves files from the current directory ('.'). Note that
the handler needs a prefix
option to specify that it must handle all
paths that begin with the registed location of the handler.
:- use_module(library(http/http_server)). :- use_module(library(http/http_files)). :- http_handler(root(.), http_reply_from_files('.', []), [prefix]). :- initialization(http_server([port(8080)]), main).
indexes
to
locate an index file (see below) or uses http_reply_dirindex/3
to create a listing of the directory.
Options:
['index.html']
.fail
makes the handler fail silently. 404
make the
handler call http_404/2. Default is fail
.
Note that this handler must be tagged as a prefix
handler (see
http_handler/3 and module introduction). This also implies that
it is possible to override more specific locations in the
hierarchy using http_handler/3 with a longer path-specifier.
When using http_handler/3 to bind this predicate to an HTTP
location, make sure it is bound to a location that ends in a /
.
When using http:location/3 to define symbolic names to HTTP
locations this is written as
http_handler(aliasname(.),
http_reply_from_files(srcdir, []),
[prefix])
.