From fd801d003bfcdfc83c2313dd3b951254f0db77ef Mon Sep 17 00:00:00 2001 From: single-right-quote <34298117+single-right-quote@users.noreply.github.com> Date: Thu, 9 Sep 2021 03:58:09 +0000 Subject: [PATCH] allow headers to refer to requested hostname, resource also document this fact --- README.md | 5 +++++ .../binaries/http-get-extra-headers.execline | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cb149d1..cd7b815 100644 --- 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 diff --git a/visible-to-httpd/binaries/http-get-extra-headers.execline b/visible-to-httpd/binaries/http-get-extra-headers.execline index 35185fa..03432b6 100755 --- a/visible-to-httpd/binaries/http-get-extra-headers.execline +++ b/visible-to-httpd/binaries/http-get-extra-headers.execline @@ -17,9 +17,16 @@ # 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`! -- 2.47.3