feat: add Forwarded header parsing and real IP extraction with tests
For issue #2694
- Added parser for the "Forwarded" header to extract the "for" field.
- Implemented real IP extraction from the "Forwarded" headers.
- Added unit tests to validate header parsing and real IP extraction functionality.
cc : @aldas
@aldas fixed lint error
cc: @aldas
cc: @aldas
Just for history sake. I did some research myself to understand what this header is and how it is implemented elsewhere
-
RFC 7239 for this
Forwardedheader https://datatracker.ietf.org/doc/html/rfc7239 -
Mozilla explanation of that header https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
-
Commit that add this header support to HAproxy https://github.com/haproxy/haproxy/commit/b2bb9257d255e5d5377d9d3ce5b2d41795207669 HAproxy
Current implementation proxy_http_parse_7239 https://github.com/haproxy/haproxy/blob/32691e7c255a944224e0ac17d0f83f217be6c5d6/src/http_ext.c#L963
-
Proposal to Go standard library
proposal: net/http/httputil: support RFC 7239 Forwarded header in ReverseProxyhttps://github.com/golang/go/issues/20526 -
old Go library that implements
Forwardedparsing https://github.com/stanvit/go-forwarded -
Discussion for Caddy to add this header support https://github.com/caddyserver/caddy/issues/3262
-
Nginx wiki about
Forwardedheader https://github.com/nginxinc/nginx-wiki/blob/master/source/start/topics/examples/forwarded.rst "Using the Forwarded header" https://trac.nginx.org/nginx/ticket/1316 -
PHP framework: Symphony commit to add support for header https://github.com/symfony/symfony/pull/11379
-
Previous PR for that header in Echo https://github.com/labstack/echo/pull/2702
This probably be better off as separate library