echo icon indicating copy to clipboard operation
echo copied to clipboard

feat: add Forwarded header parsing and real IP extraction with tests

Open debug-ing opened this issue 11 months ago • 6 comments

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.

debug-ing avatar Feb 06 '25 16:02 debug-ing

cc : @aldas

debug-ing avatar Feb 06 '25 16:02 debug-ing

@aldas fixed lint error

debug-ing avatar Feb 07 '25 17:02 debug-ing

cc: @aldas

debug-ing avatar Feb 12 '25 20:02 debug-ing

cc: @aldas

debug-ing avatar Feb 13 '25 13:02 debug-ing

Just for history sake. I did some research myself to understand what this header is and how it is implemented elsewhere

  1. RFC 7239 for this Forwarded header https://datatracker.ietf.org/doc/html/rfc7239

  2. Mozilla explanation of that header https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded

  3. 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

  4. Proposal to Go standard library proposal: net/http/httputil: support RFC 7239 Forwarded header in ReverseProxy https://github.com/golang/go/issues/20526

  5. old Go library that implements Forwarded parsing https://github.com/stanvit/go-forwarded

  6. Discussion for Caddy to add this header support https://github.com/caddyserver/caddy/issues/3262

  7. Nginx wiki about Forwarded header 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

  8. PHP framework: Symphony commit to add support for header https://github.com/symfony/symfony/pull/11379

  9. Previous PR for that header in Echo https://github.com/labstack/echo/pull/2702

aldas avatar Feb 15 '25 15:02 aldas

This probably be better off as separate library

aldas avatar Feb 15 '25 16:02 aldas