File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ func getClientIP(r *http.Request) string {
4949 if clientIP := r .Header .Get ("CF-Connecting-IP" ); clientIP != "" {
5050 return clientIP
5151 }
52+ if clientIP := r .Header .Get ("Fastly-Client-IP" ); clientIP != "" {
53+ return clientIP
54+ }
55+ if clientIP := r .Header .Get ("True-Client-IP" ); clientIP != "" {
56+ return clientIP
57+ }
5258
5359 // Try to pull a reasonable value from the X-Forwarded-For header, if
5460 // present, by taking the first entry in a comma-separated list of IPs.
Original file line number Diff line number Diff line change @@ -247,6 +247,26 @@ func TestGetClientIP(t *testing.T) {
247247 },
248248 want : "9.9.9.9" ,
249249 },
250+ "custom fastly header take precedence" : {
251+ given : & http.Request {
252+ Header : makeHeaders (map [string ]string {
253+ "Fastly-Client-IP" : "9.9.9.9" ,
254+ "X-Forwarded-For" : "1.1.1.1,2.2.2.2,3.3.3.3" ,
255+ }),
256+ RemoteAddr : "0.0.0.0" ,
257+ },
258+ want : "9.9.9.9" ,
259+ },
260+ "custom akamai header take precedence" : {
261+ given : & http.Request {
262+ Header : makeHeaders (map [string ]string {
263+ "True-Client-IP" : "9.9.9.9" ,
264+ "X-Forwarded-For" : "1.1.1.1,2.2.2.2,3.3.3.3" ,
265+ }),
266+ RemoteAddr : "0.0.0.0" ,
267+ },
268+ want : "9.9.9.9" ,
269+ },
250270 "x-forwarded-for is parsed" : {
251271 given : & http.Request {
252272 Header : makeHeaders (map [string ]string {
You can’t perform that action at this time.
0 commit comments