--- /dev/null
+#!/command/execlineb -WP
+
+importas -i httpd_execline_jail_directory httpd_execline_jail_directory
+
+export PATH /binaries
+chroot ${httpd_execline_jail_directory}
+s6-applyuidgid -U -z
+
+export program_name redirect.execline
+
+# see end of script: handle crashes cleanly
+if -X -n -t {
+ http-start-line-parse.execline
+ multisubstitute {
+ importas -i -u method http_start_line_parse_method
+ importas -i requested_resource http_start_line_parse_resource
+ }
+ ifelse -n { eltest \${method} =~ HEAD|GET }
+ {
+ http-error-response.execline
+ 501
+ "method not implemented"
+ "unsupported method: \""${method}\"
+ }
+
+ http-header-parse.execline
+ supported-hostname-test.execline
+ importas -i hostname http_header_parse_host
+
+ fdclose 0
+
+ foreground {
+ log.execline
+ "info:"
+ "client request:"
+ "for \""${hostname}\"":"
+ \"${method}\"
+ \"${requested_resource}\"":"
+ "redirecting"
+ }
+
+ # TODO: file length in bytes: SHOULD be provided
+ backtick -E -n Date { date -u "+%a, %d %b %Y %T GMT" }
+ backtick -E -n Location { s6-echo -n -- "https://"${hostname}${requested_resource} }
+ if {
+ s6-echo -n -- "HTTP/1.1 301 moved permanently\r
+Location: "${Location}"\r
+Content-Type: "application/xhtml+xml; charset=utf-8"\r
+Date: "${Date}"\r
+" }
+ if -t { eltest \${method} = GET }
+ if {
+ s6-echo -n -- "<!DOCTYPE html>
+<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
+<head>
+ <meta charset=\"utf-8\" />
+ <title>moved permanently</title>
+ <style>html {
+ background: #FFFFEA;
+ color: #303020;
+ font-family: Tinos, serif;
+ text-align: center;
+}</style></head>
+<body>
+<h1>moved permanently</h1>
+<p>this website <a href=\""${Location}"\">uses https</a></p>
+</body>
+</html>\n"
+ }
+ # hack
+ s6-sleep -m 500
+}
+ http-error-response.execline
+ 500
+ "internal server error"
+ "(i/o error? timeout?)"