summaryrefslogtreecommitdiffstats
path: root/usr.sbin/httpd
diff options
context:
space:
mode:
authorsthen <sthen@openbsd.org>2020-02-25 15:18:41 +0000
committersthen <sthen@openbsd.org>2020-02-25 15:18:41 +0000
commit603a52d71cde0c5d630cd3626cbcee06fe12e11e (patch)
tree1cf75899c18d077e25fc9d1e32fba66e3c6aa014 /usr.sbin/httpd
parentMake bwfm(4) call if_input() only once per interrupt. (diff)
downloadwireguard-openbsd-603a52d71cde0c5d630cd3626cbcee06fe12e11e.tar.xz
wireguard-openbsd-603a52d71cde0c5d630cd3626cbcee06fe12e11e.zip
httpd: allow $REQUEST_SCHEME in redirect targets, ok jung@ florian@
Sometimes you want to redirect a request to another site but maintaining the same type of connection (http or https) as the original request. Allow a $REQUEST_SCHEME variable to be used in redirect locations to allow this, e.g. location "/cgi-bin/foobar*" { block return 302 "$REQUEST_SCHEME://foobar.example.org$REQUEST_URI" }
Diffstat (limited to 'usr.sbin/httpd')
-rw-r--r--usr.sbin/httpd/httpd.conf.510
-rw-r--r--usr.sbin/httpd/server_http.c11
2 files changed, 17 insertions, 4 deletions
diff --git a/usr.sbin/httpd/httpd.conf.5 b/usr.sbin/httpd/httpd.conf.5
index 174e12be7ab..a9f3fec07c3 100644
--- a/usr.sbin/httpd/httpd.conf.5
+++ b/usr.sbin/httpd/httpd.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: httpd.conf.5,v 1.108 2020/02/09 09:44:04 florian Exp $
+.\" $OpenBSD: httpd.conf.5,v 1.109 2020/02/25 15:18:41 sthen Exp $
.\"
.\" Copyright (c) 2014, 2015 Reyk Floeter <reyk@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: February 9 2020 $
+.Dd $Mdocdate: February 25 2020 $
.Dt HTTPD.CONF 5
.Os
.Sh NAME
@@ -217,6 +217,8 @@ 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 request scheme (http or https).
.It Ic $REQUEST_URI
The request path and optional query string.
.It Ic $SERVER_ADDR
@@ -774,11 +776,13 @@ directive:
.Bd -literal -offset indent
server "example.com" {
listen on 10.0.0.1 port 80
- block return 301 "http://www.example.com$REQUEST_URI"
+ listen on 10.0.0.1 tls port 443
+ block return 301 "$REQUEST_SCHEME://www.example.com$REQUEST_URI"
}
server "www.example.com" {
listen on 10.0.0.1 port 80
+ listen on 10.0.0.1 tls port 443
}
.Ed
The request can also be rewritten with the
diff --git a/usr.sbin/httpd/server_http.c b/usr.sbin/httpd/server_http.c
index 4a46f6b44ba..d01c1eab93f 100644
--- a/usr.sbin/httpd/server_http.c
+++ b/usr.sbin/httpd/server_http.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server_http.c,v 1.136 2020/01/14 20:48:57 benno Exp $ */
+/* $OpenBSD: server_http.c,v 1.137 2020/02/25 15:18:41 sthen Exp $ */
/*
* Copyright (c) 2006 - 2018 Reyk Floeter <reyk@openbsd.org>
@@ -1148,6 +1148,15 @@ server_expand_http(struct client *clt, const char *val, char *buf,
if (ret != 0)
return (NULL);
}
+ if (strstr(val, "$REQUEST_SCHEME") != NULL) {
+ if (srv_conf->flags & SRVFLAG_TLS) {
+ ret = expand_string(buf, len, "$REQUEST_SCHEME", "https");
+ } else {
+ ret = expand_string(buf, len, "$REQUEST_SCHEME", "http");
+ }
+ if (ret != 0)
+ return (NULL);
+ }
if (strstr(val, "$SERVER_") != NULL) {
if (strstr(val, "$SERVER_ADDR") != NULL) {
if (print_host(&srv_conf->ss,