Okay, I see what’s going wrong now.
So you see that above this section, if there’s no error, Caddy returns. But if there’s an error – which is the case with basicauth because it returns an actual caddyhttp.Error(http.StatusUnauthorized, ...) – it resets the RemoteAddr on the request before it gets logged.
This functionality was implemented in this PR:
https://github.com/caddyserver/caddy/pull/3781
@matt I think we may want to rethink how this is handled, because there is a legitimate usecase for wanting the RemoteAddr to be permanently modified here.
Or… now that I think of it, maybe the realip plugin should also mutate origReq := r.Context().Value(OriginalRequestCtxKey).(http.Request) so that Caddy doesn’t need to change? But that does feel like too funky of a fix (would introduce a weird hidden behaviour).
Edit: Oh aaaaaactually, what if you add realip to handle_errors?
handle_errors {
realip
}
