From bdcd701136294f1d3a5e93047edb8bd40b54a27a Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 17 Nov 2023 22:41:16 +0000 Subject: Add X-Forwarded-For logging support Signed-off-by: Laurent Bercot --- src/libtipidee/tipidee_log_request.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/libtipidee/tipidee_log_request.c') 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 ; -- cgit v1.2.3