http_directory_listing
The http_directory_listing library provides a router-agnostic helper
for serving HTML directory listings from a configured document root
using normalized http_core request and response terms.
This library resolves a relative request path against a document root,
canonicalizes the joined target path using os::absolute_file_name/2,
rejects canonicalized escapes with the same outward 404 Not Found
response used for missing directories, and renders a simple HTML5
listing for existing directory targets.
API documentation
Open the ../../apis/library_index.html#http_directory_listing link in a web browser.
Loading
To load the library, load the loader.lgt file:
| ?- logtalk_load(http_directory_listing(loader)).
Testing
To test this library, load the tester.lgt file:
| ?- logtalk_load(http_directory_listing(tester)).
Current scope
The current version provides one public object with two public predicates:
serve/4serve/5
Supported options are:
dot_files(Boolean)directories_first(Boolean)sort_by(SortBy)sort_order(SortOrder)columns(Columns)type_display(TypeDisplay)title(Title)theme(Theme)stylesheets(Stylesheets)
Default options are:
dot_files(false)directories_first(true)sort_by(name)sort_order(ascending)columns([name, type, size, modified])type_display(simple)title('Directory listing')theme(default)stylesheets([])
Supported features:
GETandHEAD200 OKHTML directory listings for existing directory targetscanonical docroot-prefix checks after path normalization
shared document-root path sandboxing with
http_static_filesdirectory-first sorting by default, with configurable fallback to a single mixed ordering
sortable
Name,Type,Size, andModifiedcolumnsquery-driven ordering using
sort=name|type|size|modifiedandorder=ascending|descendingfor visible columns onlybreadcrumb navigation for the current directory path
parent-directory navigation for non-root listings
relative links for directory and file entries
file metadata columns for entry type, file size, and file modification time
optional column selection while keeping the
Namecolumn visibleMIME-based file-type display using
type_display(media)theme-aware CSS hooks on the generated
<body>,<table>, and entry rowsoptional stylesheet
<link>generation for custom presentation themesoptional inclusion of dot files
404 Not Foundfor missing, unsafe, or non-directory targets405 Method Not Allowedfor other methods
Presentation customization uses these option values:
columns(Columns)accepts an ordered subset of[name, type, size, modified]that must includename; hidden columns are also removed from the accepted querysort=values, with hidden or invalid sort keys falling back to the effective default visible columntype_display(simple)keeps the existingfile/directorylabels whiletype_display(media)renders MIME-based file type text such astext/plaintheme(Theme)adds atheme-ThemeCSS class to the generated<body>and<table>elementsstylesheets(Stylesheets)appends stylesheet links in the generated<head>
The generated HTML now includes stable CSS hooks such as:
bodyclasshttp-directory-listing theme-Themetableclassdirectory-listing-table theme-Theme columns-...entry row classes
entry entry-directoryandentry entry-file