From: single-right-quote <34298117+single-right-quote@users.noreply.github.com> Date: Thu, 13 Aug 2020 21:20:08 +0000 (-0400) Subject: introduce custom HTTP status pages [NEEDS WORK] X-Git-Tag: v1.0.0~49 X-Git-Url: https://git.xn--scling-oua.cat.family/?a=commitdiff_plain;h=e594b4f93df76341133fa615bde8320f54453260;p=httpd-execline.git introduce custom HTTP status pages [NEEDS WORK] 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) --- diff --git a/README.md b/README.md index 1a31099..5f77c5b 100644 --- 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. diff --git a/binaries/http-error-response.execline b/binaries/http-error-response.execline index f1e9f49..934d716 100755 --- a/binaries/http-error-response.execline +++ b/binaries/http-error-response.execline @@ -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 - +" +} + +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 -- " "${2}" diff --git a/binaries/httpd.execline b/binaries/httpd.execline index a7a6e93..cf36075 100755 --- a/binaries/httpd.execline +++ b/binaries/httpd.execline @@ -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