summaryrefslogtreecommitdiff
path: root/src/libtipidee/tipidee_log_request.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-11-17 22:41:16 +0000
committerLaurent Bercot <ska@appnovation.com>2023-11-17 22:41:16 +0000
commitbdcd701136294f1d3a5e93047edb8bd40b54a27a (patch)
tree84c5a100390c9a22140f44a7108d1918536435bb /src/libtipidee/tipidee_log_request.c
parent7ec647fa64c0a6f29cbb83cc264868b15e4bb046 (diff)
downloadtipidee-bdcd701136294f1d3a5e93047edb8bd40b54a27a.tar.xz
Add X-Forwarded-For logging support
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_log_request.c')
-rw-r--r--src/libtipidee/tipidee_log_request.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libtipidee/tipidee_log_request.c b/src/libtipidee/tipidee_log_request.c
index 6543214..54755ec 100644
--- a/src/libtipidee/tipidee_log_request.c
+++ b/src/libtipidee/tipidee_log_request.c
@@ -12,10 +12,10 @@
void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers const *hdr, stralloc *sa)
{
- char const *a[16] = { PROG, ": info:" } ;
+ char const *a[18] = { PROG, ": info:" } ;
size_t m = 2 ;
size_t start = sa->len ; /* assert: not zero */
- size_t refpos = 0, uapos = 0 ;
+ size_t refpos = 0, uapos = 0, xffpos = 0 ;
if (!(v & TIPIDEE_LOG_REQUEST)) return ;
if (!string_quotes(sa, rql->uri.path) || !stralloc_0(sa)) goto eerr ;
if (v & TIPIDEE_LOG_REFERRER)
@@ -36,6 +36,15 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers co
if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
}
}
+ if (v & TIPIDEE_LOG_XFORWARDEDFOR)
+ {
+ char const *x = tipidee_headers_search(hdr, "X-Forwarded-For") ;
+ if (x)
+ {
+ xffpos = sa->len ;
+ if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ;
+ }
+ }
if (v & TIPIDEE_LOG_HOSTASPREFIX)
{
a[m++] = " host " ;
@@ -67,6 +76,11 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers co
a[m++] = " user-agent " ;
a[m++] = sa->s + uapos ;
}
+ if (xffpos)
+ {
+ a[m++] = " x-forwarded-for " ;
+ a[m++] = sa->s + xffpos ;
+ }
strerr_warnv(a, m) ;
sa->len = start ;
return ;