Skip to content

Ability to override request.ip (and maybe omit it entirely) #15

@ItalyPaleAle

Description

@ItalyPaleAle

Thanks for this package, it's exactly what I needed.

My only problem is that the app is behind a proxy, so r.RemoteAddr is always the IP of the proxy, which is of limited use. It would be very helpful to be able to alter this value, for example so it's read from a configurable header.

I think this could be implemented in two ways:

  1. Add an option for the sloghttp object that is a callback that allows returning the IP of the client, so the app developer will choose how to compute that
  2. Allow specifying the IP ranges of "trusted proxies" (e.g. TrustedProxies: []string{"10.0.0.0/8"}). When RemoteAddr is the one of a trusted proxy, read the value of X-Forwarded-For. It should be possible to make the header's name configurable too (e.g. use X-Real-IP or something else)

While we're at it, I think it would be helpful to add an option to omit the IP entirely in the log, since IPs are normally considered PII and can create compliance issues with privacy regulations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions