Add target prefix mapping
This allows e.g. to redirect when a directory has been moved.
This commit is contained in:
parent
02d6ae5a57
commit
7b7f166dd5
2 changed files with 28 additions and 0 deletions
10
config.def.h
10
config.def.h
|
@ -25,6 +25,16 @@ static struct {
|
|||
{ "example.org", "old\\.example\\.org", "/", "/old" },
|
||||
};
|
||||
|
||||
/* 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;
|
||||
|
|
18
http.c
18
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", map[i].to,
|
||||
realtarget + len) >= sizeof(realtarget)) {
|
||||
return http_send_status(fd, S_REQUEST_TOO_LARGE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* normalize target */
|
||||
if (normabspath(realtarget)) {
|
||||
return http_send_status(fd, S_BAD_REQUEST);
|
||||
|
|
Loading…
Reference in a new issue