Skip to content

Commit

Permalink
Simpler and actually correct x-forwarded-for fix
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Dec 19, 2024
1 parent dafafda commit ac17fd0
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions proxyfilters/forwardedfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package proxyfilters
import (
"net"
"net/http"
"strings"

"github.com/getlantern/proxy/v3/filters"
)
Expand All @@ -17,10 +16,7 @@ const (
var AddForwardedFor = filters.FilterFunc(func(cs *filters.ConnectionState, req *http.Request, next filters.Next) (*http.Response, *filters.ConnectionState, error) {
if req.Method != http.MethodConnect {
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
if prior, ok := req.Header[xForwardedFor]; ok {
clientIP = strings.Join(prior, ", ") + ", " + clientIP
}
req.Header.Set(xForwardedFor, clientIP)
req.Header.Add(xForwardedFor, clientIP)
}
}
return next(cs, req)
Expand Down

0 comments on commit ac17fd0

Please sign in to comment.