mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-30 12:05:38 +00:00
Pass X-Real-IP to handlers.CombinedLoggingHandler
Note that X-Forwarded-For or guessed client IP are not used due to security concerns. This should fix issue #71.
This commit is contained in:
@@ -136,6 +136,18 @@ func (s *Server) Start() error {
|
||||
func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
if realIP := r.Header.Get("X-Real-IP"); realIP != "" {
|
||||
if strings.ContainsRune(realIP, ':') {
|
||||
r.RemoteAddr = "[" + realIP + "]:0"
|
||||
} else {
|
||||
r.RemoteAddr = realIP + ":0"
|
||||
}
|
||||
_, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
r.RemoteAddr = realIP
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, POST")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
Reference in New Issue
Block a user