From 8cc893f5a55ad27a6971524b41e99589576eade5 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Tue, 13 Dec 2011 19:50:52 +0100 Subject: [PATCH] dirplex, patplex: Added a cosmetical `xset' directive to supplant `set'. --- doc/dirplex.doc | 11 +++++++++-- doc/patplex.doc | 7 +++++++ src/dirplex/conf.c | 9 ++++++--- src/patplex.c | 9 ++++++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/doc/dirplex.doc b/doc/dirplex.doc index 9f3aab2..fe21c7e 100644 --- a/doc/dirplex.doc +++ b/doc/dirplex.doc @@ -261,8 +261,8 @@ following actions are recognized: by a *fchild* stanza. This action exists mostly for convenience. -A *match* stanza may also contain any number of *set* lines, as -follows: +A *match* stanza may also contain any number of the following, +optional directives: *set* 'HEADER' 'VALUE':: @@ -270,6 +270,13 @@ follows: named HTTP 'HEADER' in the request is set to 'VALUE' before passing the request on to the specified handler. +*xset* 'HEADER' 'VALUE':: + + *xset* does exactly the same thing as *set*, except the + 'HEADER' is automatically prepended with the `X-Ash-` + prefix. The intention is only to make configuration files + look nicer in this very common case. + 404 RESPONSES ------------- diff --git a/doc/patplex.doc b/doc/patplex.doc index d2ee009..f567d56 100644 --- a/doc/patplex.doc +++ b/doc/patplex.doc @@ -111,6 +111,13 @@ optional lines: request on to the specified handler. A *match* stanza may contain any number of *set* lines. +*xset* 'HEADER' 'VALUE':: + + *xset* does exactly the same thing as *set*, except the + 'HEADER' is automatically prepended with the `X-Ash-` + prefix. The intention is only to make configuration files + look nicer in this very common case. + *restpat* 'TEMPLATE':: If the *match* stanza as a whole matches, 'TEMPLATE' is diff --git a/src/dirplex/conf.c b/src/dirplex/conf.c index e2b1481..3f9f9e8 100644 --- a/src/dirplex/conf.c +++ b/src/dirplex/conf.c @@ -185,13 +185,16 @@ static struct pattern *parsepattern(struct cfstate *s) pat->childnm = sstrdup(s->argv[1]); } else if(!strcmp(s->argv[0], "fork")) { pat->fchild = cadup(s->argv + 1); - } else if(!strcmp(s->argv[0], "set")) { + } else if(!strcmp(s->argv[0], "set") || !strcmp(s->argv[0], "xset")) { if(s->argc < 3) { - flog(LOG_WARNING, "%s:%i: missing header name or pattern for `set' directive", s->file, s->lno); + flog(LOG_WARNING, "%s:%i: missing header name or pattern for `%s' directive", s->file, s->lno, s->argv[0]); continue; } omalloc(head); - head->name = sstrdup(s->argv[1]); + if(!strcmp(s->argv[0], "xset")) + head->name = sprintf2("X-Ash-%s", s->argv[1]); + else + head->name = sstrdup(s->argv[1]); head->value = sstrdup(s->argv[2]); head->next = pat->headers; pat->headers = head; diff --git a/src/patplex.c b/src/patplex.c index b03b626..5506386 100644 --- a/src/patplex.c +++ b/src/patplex.c @@ -249,13 +249,16 @@ static struct pattern *parsepattern(struct cfstate *s) if(pat->restpat != NULL) free(pat->restpat); pat->restpat = sstrdup(s->argv[1]); - } else if(!strcmp(s->argv[0], "set")) { + } else if(!strcmp(s->argv[0], "set") || !strcmp(s->argv[0], "xset")) { if(s->argc < 3) { - flog(LOG_WARNING, "%s:%i: missing header name or pattern for `set' directive", s->file, s->lno); + flog(LOG_WARNING, "%s:%i: missing header name or pattern for `%s' directive", s->file, s->lno, s->argv[0]); continue; } omalloc(head); - head->name = sstrdup(s->argv[1]); + if(!strcmp(s->argv[0], "xset")) + head->name = sprintf2("X-Ash-%s", s->argv[1]); + else + head->name = sstrdup(s->argv[1]); head->value = sstrdup(s->argv[2]); head->next = pat->headers; pat->headers = head; -- 2.11.0