aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2022-01-02 16:33:28 +0000
committerOmar Polo <op@omarpolo.com>2022-01-02 16:33:28 +0000
commitb7967bc1f695126e1bf2705bfd486bbc32aaf8b0 (patch)
treed24f103eb78223a61049bfcebedb1686bd628c3c /server.c
parente2f167afb3444d3ba55fdffe234ef7812cac72f0 (diff)
proxy: allow multiple proxy blocks, matching options and validations
as a side effect the order of the content of a server block is relaxed: options, location or proxy blocks can be put in any order.
Diffstat (limited to 'server.c')
-rw-r--r--server.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/server.c b/server.c
index 2a4ed66..991e126 100644
--- a/server.c
+++ b/server.c
@@ -605,6 +605,31 @@ apply_block_return(struct client *c)
return 1;
}
+static struct proxy *
+matched_proxy(struct client *c)
+{
+ struct proxy *p;
+ const char *proto;
+ const char *host;
+ const char *port;
+
+ TAILQ_FOREACH(p, &c->host->proxies, proxies) {
+ if ((proto = p->match_proto) == NULL)
+ proto = "gemini";
+ if ((host = p->match_host) == NULL)
+ host = "*";
+ if ((port = p->match_port) == NULL)
+ port = "*";
+
+ if (matches(proto, c->iri.schema) &&
+ matches(host, c->domain) &&
+ matches(port, c->iri.port))
+ return p;
+ }
+
+ return NULL;
+}
+
/* 1 if matching a proxy relay-to (and apply it), 0 otherwise */
static int
apply_reverse_proxy(struct client *c)
@@ -612,18 +637,17 @@ apply_reverse_proxy(struct client *c)
struct proxy *p;
struct connreq r;
- p = &c->host->proxy;
- if (p->host == NULL)
+ if ((p = matched_proxy(c)) == NULL)
return 0;
+ c->proxy = p;
+
log_debug(c, "opening proxy connection for %s:%s",
p->host, p->port);
strlcpy(r.host, p->host, sizeof(r.host));
strlcpy(r.port, p->port, sizeof(r.port));
- strlcpy(c->domain, p->host, sizeof(c->domain));
-
imsg_compose(&exibuf, IMSG_CONN_REQ, c->id, 0, -1, &r, sizeof(r));
imsg_flush(&exibuf);