]> cat aescling's git repositories - httpd-execline.git/commitdiff
allow headers to refer to requested hostname, resource
authorsingle-right-quote <34298117+single-right-quote@users.noreply.github.com>
Thu, 9 Sep 2021 03:58:09 +0000 (03:58 +0000)
committersingle-right-quote <34298117+single-right-quote@users.noreply.github.com>
Thu, 9 Sep 2021 03:58:09 +0000 (03:58 +0000)
also document this fact

README.md
visible-to-httpd/binaries/http-get-extra-headers.execline

index cb149d105a2be9a4715057cd9e82cc34019fd648..cd7b8152ea2eacb0cddc3ca41010f405e0e3541a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -119,6 +119,11 @@ a `Strict-Transport-Security` file is a good idea; if you find it
 prudent to allow access as an onion service, an `Onion-Location` file
 is a good idea. and so on.
 
+the hostname and requested resource for the current request will be
+substituted for all instances of `${hostname}` and `${resource}` in
+the header contents, which might prove useful for the `Location` and
+`Onion-Location` headers.
+
 `\r` and newlines will be stripped from filenames and file contents to
 prevent trivial mischevious configurations from breaking HTTP
 responses; other than this, **these HTTP header folders are not
index 35185fae40ac6c86ff0b5ccc2bf640d7f38d77f6..03432b6840902bc8e333f0b0b4d38499b75df8fb 100755 (executable)
 # TODO: write a GUI?? with like, `yad(1)` or something??? idk
 
 multisubstitute {
-       importas -D -fallback hostname http_header_parse_Host
+       importas -D -no_hostname_parsed hostname http_header_parse_Host
+       importas -i requested_resource http_start_line_parse_resource
        importas -i resource resource
 }
+define header_substitution_script
+"multisubstitute {
+       define hostname "${hostname}"
+       define resource "${requested_resource}"
+}
+s6-echo -n -- "
 
 backtick -x -n header-directory {
        # for status code pages specifically
@@ -82,9 +89,13 @@ if -t { s6-test -v header-directory }
                        tr -d "\r\n"
                }
                if {
-                       pipeline { cat ${header_name} }
-                       tr -d "\r\n"
+                       backtick -E -n unparsed_header_contents {
+                               pipeline { cat ${header_name} }
+                               tr -d "\r\n"
+                       }
+                       execlineb -WPc ${header_substitution_script}${unparsed_header_contents}
                }
+
                s6-echo -n -- "\r\n"
        # do remember to add the terminating `\r\n`!