it takes a lot of inspiration from
[publicfile](https://cr.yp.to/publicfile.html), while trying to allow some level
-of customization (custom HTTP headers, file-extension/MIME-type mapping
-adjustments) without requiring you to edit code; here we use using a
-filesystem-driven configuration where the hierarchical file structure amounts to
-a simple structured key-value store.
+of customization (custom error status pages, custom HTTP headers,
+file-extension/MIME-type mapping adjustments) without requiring you to edit
+code; here we use using a filesystem-driven configuration where the hierarchical
+file structure amounts to a simple structured key-value store.
\* “simple” here better describes functionality than implementation.
#!/binaries/execlineb -WS2
# http-error-response.execline STATUS_CODE STATUS_MESSAGE [LOG_MESSAGE]
+#
+# if `data/status-code/table/${hostname}/${STATUS_CODE} exists, `cat(1)` that
+# otherwise, fall back on a very generic error message
+#
+# TODO:
+# + handle headers for custom status code files
+# + related to above: get `Content-Length` correct
fdclose 0
foreground {
backtick -i -n extra_headers { cat data/extra_headers/default }
multisubstitute {
- importas -i -u Content-Length Content-Length
+# TODO: importas -i -u Content-Length Content-Length
importas -i -u Date Date
importas -i -u extra_headers extra_headers
+ importas -D "invalid default hostname which should not match any hostname directory" hostname http_header_parse_Host
}
if {
s6-echo -n -- "HTTP/1.1 "${1}" "${2}"\r
Content-Type: application/xhtml+xml; charset=utf-8\r
-Content-Length: "${Content-Length}"\r
Date: "${Date}"\r
"${extra_headers}"\r
\r
-<!DOCTYPE html>
+"
+}
+
+if {
+ ifelse { s6-test -r data/status-code_table/${hostname}/${1} }
+ {
+ # TODO: support `Content-Types`?? and `Content-Length`
+ cat data/status-code_table/${hostname}/${1}
+ }
+ s6-echo -n -- "<!DOCTYPE html>
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
<head>
<meta charset=\"utf-8\" />
<title>"${2}"</title>
<style>html {
- background: #FFFFEA;
- color: #303020;
+ background: #F0E0BB;
+ color: #302011;
font-family: Tinos, serif;
text-align: center;
}</style>
##### 2.1. start line ###
http-start-line-parse.execline
multisubstitute {
- importas -i -u method http_start_line_parse_method
- importas -i -u requested_resource http_start_line_parse_resource
+ importas -i method http_start_line_parse_method
+ importas -i requested_resource http_start_line_parse_resource
}
ifelse -n {
s6-test \${method} = HEAD -o
# http_header_parse_${Header_Name}.
# that said, we use only `Host` here.
# `/http-header-parse.execline` is implemented in a wonderfully silly way
- importas -i -u hostname http_header_parse_Host
+ importas -i hostname http_header_parse_Host
# we don’t need to read anything more from the client
fdclose 0