zerolog icon indicating copy to clipboard operation
zerolog copied to clipboard

hlog.RemoteAddrHandler() not working when real-ip is set by chi middleware.RealIP

Open spartakb opened this issue 6 years ago • 2 comments

When using the application behind a reverse proxy, it's helpful to have a middleware that takes the X-Real-IP Header and sets the http.Request RemoteAddr.

However, in doing so, sometimes the port number does not get set by the middleware, in my case by the chi middleware.RealIP

When this happens, the hlog.RemoteAddrHandler fails during the net.SplitHostPort() attempt.

Suggestion is to update hlog.RemoteAddrHandler function so that it can handle cases where the RemoteAddr only has the ip 1.2.3.4 instead of the full fledged ip:port (1.2.3.4:5555) combination.

spartakb avatar Nov 11 '19 06:11 spartakb

@spartakb I'm not sure it is relevant. But I added hlog.CustomHeaderHandler to handle some use cases like this. #197 I believe you can use this to log X-Real-IP Header instead of using RemoteAddr.

hlog.RemoteAddrHandler looks very simple and clean. Not sure it should be changed to handle that kind of cases.

aca avatar Dec 30 '19 12:12 aca