MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / replaceRemoteAddr

Method replaceRemoteAddr

server/router.go:235–251  ·  view source on GitHub ↗

replaceRemoteAddr rewrites the req.RemoteAddr property from request headers

(req *http.Request)

Source from the content-addressed store, hash-verified

233
234// replaceRemoteAddr rewrites the req.RemoteAddr property from request headers
235func (r *Router) replaceRemoteAddr(req *http.Request) {
236 cfConnectingIP := req.Header.Get(httpheaders.CFConnectingIP)
237 xForwardedFor := req.Header.Get(httpheaders.XForwardedFor)
238 xRealIP := req.Header.Get(httpheaders.XRealIP)
239
240 switch {
241 case len(cfConnectingIP) > 0:
242 replaceRemoteAddr(req, cfConnectingIP)
243 case len(xForwardedFor) > 0:
244 if index := strings.Index(xForwardedFor, ","); index > 0 {
245 xForwardedFor = xForwardedFor[:index]
246 }
247 replaceRemoteAddr(req, xForwardedFor)
248 case len(xRealIP) > 0:
249 replaceRemoteAddr(req, xRealIP)
250 }
251}
252
253// replaceRemoteAddr sets the req.RemoteAddr for request
254func replaceRemoteAddr(req *http.Request, ip string) {

Callers 1

ServeHTTPMethod · 0.95

Calls 2

replaceRemoteAddrFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected