]> cat aescling's git repositories - httpd-execline.git/commitdiff
introduce custom HTTP status pages [NEEDS WORK]
authorsingle-right-quote <34298117+single-right-quote@users.noreply.github.com>
Thu, 13 Aug 2020 21:20:08 +0000 (17:20 -0400)
committersingle-right-quote <34298117+single-right-quote@users.noreply.github.com>
Fri, 14 Aug 2020 19:08:14 +0000 (19:08 +0000)
as an additional bonus, child processes of `httpd.execline` now inherit
the environment variables for the parsed start line and headers; this
allows `http-error-response.execline` to make use of the host supplied
by the client request with minimal changes.

note that `Content-Length` is currently not supplied anymore for header
responses (functional, but the HTTP/1.1 standard says you “SHOULD” use
that header); this needs fixing.

also note that `http-error-response.execline` currently forces error
status pages to use a `Content-Type` of
`application/xhtml+xml; charset=utf-8`; surely we should allow the user
to override this. (perhaps make status code *folders*, and use
constituent files `Content-Type`, perhaps `extra_headers`, and of course
`message_body`, in that directory? this interface would be less than
ideal though)

README.md
binaries/http-error-response.execline
binaries/httpd.execline

index 1a310997cb1f3cb5f03889d5abe2119070494a65..5f77c5bd06dc2cbb26fdfc13827073932d8f9510 100644 (file)
--- a/README.md
+++ b/README.md
@@ -9,10 +9,10 @@ is that it is far less verbose.)
 
 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.
 
index f1e9f4979caa0e2082435126e89e2eb261c33753..934d716e99b5a0e131aa668a6bac650c2c13d9ad 100755 (executable)
@@ -1,5 +1,12 @@
 #!/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 {
@@ -24,26 +31,35 @@ backtick -i -n Date { date -u "+%a, %d %b %Y %T GMT" }
 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>
index a7a6e930623fde1b002319ec839cdb8ce062a4d8..cf3607546e872751190897b9e29ec2909bcf6adf 100755 (executable)
@@ -66,8 +66,8 @@ if -X -n -t {
        ##### 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
@@ -88,7 +88,7 @@ if -X -n -t {
        # 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