mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fix realIP middleware not getting IP in some cases
This commit is contained in:
parent
942651dc16
commit
f683ab64ab
2 changed files with 6 additions and 1 deletions
|
@ -38,7 +38,7 @@ var CloudflareRealIP = NewMiddleware[cloudflareRealIP]()
|
|||
// setup implements MiddlewareWithSetup.
|
||||
func (cri *cloudflareRealIP) setup() {
|
||||
cri.realIP.RealIPOpts = RealIPOpts{
|
||||
Header: "CF-Connecting-IP",
|
||||
Header: "Cf-Connecting-Ip",
|
||||
Recursive: cri.Recursive,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,11 @@ func (ri *realIP) setRealIP(req *http.Request) {
|
|||
realIPs := req.Header.Values(ri.Header)
|
||||
lastNonTrustedIP := ""
|
||||
|
||||
if len(realIPs) == 0 {
|
||||
// try non-canonical key
|
||||
realIPs = req.Header[ri.Header]
|
||||
}
|
||||
|
||||
if len(realIPs) == 0 {
|
||||
ri.AddTracef("no real ip found in header %s", ri.Header).WithRequest(req)
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue