The patch below adds a "$REQUEST_SCHEME" macro to those available in
block rules in httpd.conf

Justification: when redirecting from a (virtual) server which supports
both http and https to a (virtual) server which also supports both
schemes, it make sense to be able to respect (preserve) the scheme of
the original request rather than having to hard-code "http" or "https".

Patch is against -current, but has been tested (only) against
5.9-stable.

Ross


Index: src/usr.sbin/httpd/httpd.conf.5
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
retrieving revision 1.73
diff -u -p -u -r1.73 httpd.conf.5
--- src/usr.sbin/httpd/httpd.conf.5     9 May 2016 19:36:54 -0000       1.73
+++ src/usr.sbin/httpd/httpd.conf.5     22 Jun 2016 11:16:01 -0000
@@ -202,7 +202,7 @@ The
 .Ar uri
 may contain predefined macros that will be expanded at runtime:
 .Pp
-.Bl -tag -width $DOCUMENT_URI -offset indent -compact
+.Bl -tag -width $REQUEST_SCHEME -offset indent -compact
 .It Ic $DOCUMENT_URI
 The request path.
 .It Ic $QUERY_STRING
@@ -213,6 +213,14 @@ The IP address of the connected client.
 The TCP source port of the connected client.
 .It Ic $REMOTE_USER
 The remote user for HTTP authentication.
+.It Ic $REQUEST_SCHEME
+The scheme
+.Po
+.Dq http
+or
+.Dq https
+.Pc
+of the request.
 .It Ic $REQUEST_URI
 The request path and optional query string.
 .It Ic $SERVER_ADDR
Index: src/usr.sbin/httpd/server_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.108
diff -u -p -u -r1.108 server_http.c
--- src/usr.sbin/httpd/server_http.c    27 May 2016 11:24:13 -0000      1.108
+++ src/usr.sbin/httpd/server_http.c    22 Jun 2016 11:16:01 -0000
@@ -1011,6 +1011,12 @@ server_expand_http(struct client *clt, c
                if (ret != 0)
                        return (NULL);
        }
+       if (strstr(val, "$REQUEST_SCHEME") != NULL) {
+               ret = expand_string(buf, len, "$REQUEST_SCHEME",
+                   clt->clt_tls_ctx != NULL ? "https" : "http");
+               if (ret != 0)
+                       return (NULL);
+       }
        if (strstr(val, "$SERVER_") != NULL) {
                if (strstr(val, "$SERVER_ADDR") != NULL) {
                        if (print_host(&srv_conf->ss,

Reply via email to