mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-29 23:39:35 -05:00
c284b4d07b
git-subtree-dir: ocis-pkg git-subtree-mainline:4c12bed11bgit-subtree-split:72d605ba38
19 lines
350 B
Go
19 lines
350 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/tomasen/realip"
|
|
)
|
|
|
|
// RealIP is a middleware that sets a http.Request RemoteAddr.
|
|
func RealIP(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if ip := realip.RealIP(r); ip != "" {
|
|
r.RemoteAddr = ip
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|