From: Fredrik Tolf Date: Wed, 9 Aug 2023 17:11:33 +0000 (+0200) Subject: accesslog: Add %p and %P format options. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=5a723273828ffc7b3889e538344c65cc15eb3696;p=ashd.git accesslog: Add %p and %P format options. --- diff --git a/doc/accesslog.doc b/doc/accesslog.doc index 2baf508..7a8e8e9 100644 --- a/doc/accesslog.doc +++ b/doc/accesslog.doc @@ -199,6 +199,17 @@ instead expand into a dash. Expands into the time it took for the handler to complete the response, expressed as seconds with 6 decimals precision. +*%{*'HEADER'*}p*:: + + Expands into the HTTP response header named by 'HEADER'. If + the specified header does not exist in the request, *%p* + expands into a dash. + +*%{*'HEADER'*}P*:: + + Similar to *%p*, except that 'HEADER' is prepended with + `X-Ash-`, for simple convenience. + In any expanded field, any "unsafe" characters are escaped. Currently, this means that double-quotes and backslashes are prepended with a backslash, newlines and tabs are expressed as, respectively, `\n` and diff --git a/src/accesslog.c b/src/accesslog.c index af43373..7c550dd 100644 --- a/src/accesslog.c +++ b/src/accesslog.c @@ -96,6 +96,16 @@ static void logitem(struct logdata *data, char o, char *d) qputs(h, out); } break; + case 'p': + if(!data->resp || ((h = getheader(data->req, d)) == NULL)) { + putc('-', out); + } else { + qputs(h, out); + } + break; + case 'P': + logitem(data, 'p', sprintf3("X-Ash-%s", d)); + break; case 'u': qputs(data->req->url, out); break;