diff options
-rw-r--r-- | usr.sbin/relayd/relay_http.c | 25 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.conf.5 | 6 |
2 files changed, 25 insertions, 6 deletions
diff --git a/usr.sbin/relayd/relay_http.c b/usr.sbin/relayd/relay_http.c index e0ddadee46d..d0dfd35cacf 100644 --- a/usr.sbin/relayd/relay_http.c +++ b/usr.sbin/relayd/relay_http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay_http.c,v 1.76 2019/05/13 15:19:16 reyk Exp $ */ +/* $OpenBSD: relay_http.c,v 1.77 2019/07/05 13:42:06 robert Exp $ */ /* * Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org> @@ -1126,13 +1126,30 @@ char * relay_expand_http(struct ctl_relay_event *cre, char *val, char *buf, size_t len) { - struct rsession *con = cre->con; - struct relay *rlay = con->se_relay; - char ibuf[128]; + struct rsession *con = cre->con; + struct relay *rlay = con->se_relay; + struct http_descriptor *desc = cre->desc; + struct kv *host, key; + char ibuf[128]; if (strlcpy(buf, val, len) >= len) return (NULL); + if (strstr(val, "$HOST") != NULL) { + key.kv_key = "Host"; + host = kv_find(&desc->http_headers, &key); + if (host) { + if (host->kv_value == NULL) + return (NULL); + snprintf(ibuf, sizeof(ibuf), "%s", host->kv_value); + } else { + if (print_host(&rlay->rl_conf.ss, + ibuf, sizeof(ibuf)) == NULL) + return (NULL); + } + if (expand_string(buf, len, "$HOST", ibuf)) + return (NULL); + } if (strstr(val, "$REMOTE_") != NULL) { if (strstr(val, "$REMOTE_ADDR") != NULL) { if (print_host(&cre->ss, ibuf, sizeof(ibuf)) == NULL) diff --git a/usr.sbin/relayd/relayd.conf.5 b/usr.sbin/relayd/relayd.conf.5 index e5c8fa97df6..f45585565ed 100644 --- a/usr.sbin/relayd/relayd.conf.5 +++ b/usr.sbin/relayd/relayd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayd.conf.5,v 1.191 2019/06/26 12:13:47 reyk Exp $ +.\" $OpenBSD: relayd.conf.5,v 1.192 2019/07/05 13:42:06 robert Exp $ .\" .\" Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org> .\" Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -15,7 +15,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: June 26 2019 $ +.Dd $Mdocdate: July 5 2019 $ .Dt RELAYD.CONF 5 .Os .Sh NAME @@ -1318,6 +1318,8 @@ The value string may contain predefined macros that will be expanded at runtime: .Pp .Bl -tag -width $SERVER_ADDR -offset indent -compact +.It Ic $HOST +The Host header's value of the relay. .It Ic $REMOTE_ADDR The IP address of the connected client. .It Ic $REMOTE_PORT |