]> cat aescling's git repositories - httpd-execline.git/commitdiff
Implement Content-Type override
authorcat æscling <11325618-aescling@users.noreply.gitlab.com>
Tue, 25 Jul 2023 23:33:07 +0000 (19:33 -0400)
committercat æscling <11325618-aescling@users.noreply.gitlab.com>
Wed, 26 Jul 2023 00:48:52 +0000 (00:48 +0000)
Document accordingly

Ignore any Content-Type headers in
`configuration/override/${resource}/headers`

* Remove empty line comments

README.md
visible-to-httpd/binaries/http-print-header-files.execline
visible-to-httpd/binaries/httpd.execline

index 7b51078b5085a41bbab4cfedbdc2714bb39d592f..a209adca602c9053a671ee54d37d2d5f2dc08698 100644 (file)
--- a/README.md
+++ b/README.md
@@ -96,7 +96,7 @@ will be served with a `Content-Type` of `{1}/${2}` (with colons in
 `index.text=x:market` will always be served with a `Content-Type` of
 `text/x.market`.
 2. using the per-resource `overrides` folder (see below) to specify a
-`Content-Type` header explicitly.
+`Content-Type` header explicitly (but not in the `headers` subdirectory).
 
 #### `./visible-to-httpd/configuration/default_headers/` ###
 
@@ -147,9 +147,13 @@ this directory allows you to override the extra headers sent along
 with a resource, and attach a status code other than 200 with them. a
 folder named after the specific resource (including a prepended
 hostname) should may contain a `status_code` file containing a
-numerical status code and optional textual message, as well as a
+numerical status code and optional textual message, a
 `headers` folder, which specifies headers using the `default_headers`
-scheme.
+scheme, and a `Content-Type` file, to override any other mechanism for
+determining the Content-Type to send to the client.
+
+Note that a `Content-Type` file in the `headers` folder is always
+ignored.
 
 a former official website for `httpd-execline.eerie.garden`
 used to redirect to this github repository, thanks to
index 230d976a5d6ee74320dfb30fa4b6e7d3fd62c350..9886081353abef5b41edd05c6323386653797961 100755 (executable)
@@ -6,6 +6,8 @@
 # instances of ${hostname} and ${resource} are substituted with the provided
 # host and resource from the request
 #
+# the script will refuse to override the Content-Type header
+#
 # execs into self in order to retain an environment variable which marks
 # whether a certain header has been overridden or not
 
@@ -31,6 +33,15 @@ backtick -E -n header_name {
        sed "s@.*/([^/]*)@\\1@"
 }
 
+ifelse {
+       pipeline { s6-echo -n -- \${header_name} }
+       grep -s -i '^[  ]*Content-Type[         ]*$' # paranoid whitespace matching
+}
+{
+       foreground { log.execline "refusing to override Content-Type header" }
+       http-print-header-directories.execline ${@}
+}
+
 # short circuit on overridden header
 ifelse { s6-test -v http_print_header_directories_${header_name} }
 {
index b38f3dd754c233e5314a22a64e5296942e90e760..2860e6ec320900cf559683f5c93f0e6c26790aab 100755 (executable)
@@ -147,8 +147,13 @@ if -X -n -t {
 
        #### 4. send response ###
        ##### 4.1. determine found resource's Content-Type ###
-       #
        backtick -i -n Content-Type {
+               define Content_Type_override_file configuration/overrides/${resourse}/Content-Type
+               ifelse { s6-test -f ${Content_Type_override_file} -a -r ${Content_Type_override_file} }
+               {
+                       cat ${Content_Type_override_file}
+               }
+
                backtick -D "no.extension" -n extension {
                        pipeline { printenv resource }
                        # strip everything up to the non-periods after the final
@@ -162,12 +167,9 @@ if -X -n -t {
                # with `Content-Type` `${1}/${2}`. colons in the extension are
                # transformed into periods, allowing files like
                # `index.text=x:market` being served as `text/x.market`
-               #
-               # this overrides any other Content-Type determination mechanism
                ifelse {
                        pipeline { printenv extension }
                        # this regex matches exactly what `publicfile` does
-                       #
                        grep -s "[a-zA-Z0-9]+=[^=]+$"
                }
                {