Introduction
Introduction Statistics Contact Development Disclaimer Help
Add target prefix mapping - quark - quark web server
git clone git://git.suckless.org/quark
Log
Files
Refs
LICENSE
---
commit 7b7f166dd58b572989d3980f973d9ed88325ece8
parent 02d6ae5a5714ad24ea0d56a1d575c3dc72bb6949
Author: Laslo Hunhold <[email protected]>
Date: Tue, 27 Feb 2018 12:43:05 +0100
Add target prefix mapping
This allows e.g. to redirect when a directory has been moved.
Diffstat:
M config.def.h | 10 ++++++++++
M http.c | 18 ++++++++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/config.def.h b/config.def.h
@@ -25,6 +25,16 @@ static struct {
{ "example.org", "old\\.example\\.org", "/", …
};
+/* target prefix mapping */
+static const struct {
+ const char *vhost;
+ const char *from;
+ const char *to;
+} map[] = {
+ /* canonical host from to */
+ { "example.org", "/old/path/to/dir", "/new/path/to/dir" },
+};
+
/* mime-types */
static const struct {
char *ext;
diff --git a/http.c b/http.c
@@ -351,6 +351,24 @@ http_send_response(int fd, struct request *r)
}
}
+ /* apply target prefix mapping */
+ for (i = 0; i < LEN(map); i++) {
+ len = strlen(map[i].from);
+ if (!strncmp(realtarget, map[i].from, len)) {
+ /* match canonical host if vhosts are enabled */
+ if (vhosts && strcmp(map[i].vhost, vhostmatch)) {
+ continue;
+ }
+
+ /* swap out target prefix */
+ if (snprintf(realtarget, sizeof(realtarget), "%s%s", m…
+ realtarget + len) >= sizeof(realtarget)) {
+ return http_send_status(fd, S_REQUEST_TOO_LARG…
+ }
+ break;
+ }
+ }
+
/* normalize target */
if (normabspath(realtarget)) {
return http_send_status(fd, S_BAD_REQUEST);
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.