Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Aszalos <gabriel.aszalos@gmail.com>
  • Loading branch information
Hellzy and gbbr committed Jun 9, 2022
1 parent 7c475c0 commit ca69977
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions contrib/internal/httptrace/httptrace.go
Expand Up @@ -95,21 +95,17 @@ func getClientIP(remoteAddr string, headers http.Header, clientIPHeader string)
ipHeaders = []string{clientIPHeader}
}
check := func(value string) netaddr.IP {
for _, ip := range strings.Split(value, ",") {
ipStr := strings.Trim(ip, " ")
ip := parseIP(ipStr)

for _, ipstr := range strings.Split(value, ",") {
ip := parseIP(strings.TrimSpace(ipstr))
if !ip.IsValid() {
continue
}

if isGlobal(ip) {
return ip
}
}
return netaddr.IP{}
}

for _, hdr := range ipHeaders {
if value := headers.Get(hdr); value != "" {
if ip := check(value); ip.IsValid() {
Expand Down
2 changes: 1 addition & 1 deletion contrib/internal/httptrace/options_test.go
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestConfig(t *testing.T) {
t.Run("config", func(t *testing.T) {
t.Run("client-ip", func(t *testing.T) {
t.Run("client-ip-header-unset", func(t *testing.T) {
cfg := newConfig()
require.Empty(t, cfg.ipHeader)
Expand Down

0 comments on commit ca69977

Please sign in to comment.