Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions bitswap/network/httpnet/httpnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,44 @@
}

// WithAllowlist sets the hostnames that we are allowed to connect to via
// HTTP. Additionally, http response status metrics are tagged for each of
// these hosts.
// HTTP.
func WithAllowlist(hosts []string) Option {
return func(net *Network) {
log.Infof("HTTP retrieval allowlist: %s", strings.Join(hosts, ", "))
net.allowlist = make(map[string]struct{})
for _, h := range hosts {
h = strings.TrimSpace(h)
if h == "" {
log.Error("empty string in allowlist. Ignoring...")
continue

Check warning on line 132 in bitswap/network/httpnet/httpnet.go

View check run for this annotation

Codecov / codecov/patch

bitswap/network/httpnet/httpnet.go#L129-L132

Added lines #L129 - L132 were not covered by tests
}
if strings.Contains(h, " ") {
log.Errorf("allowlist item '%s' contains a whitespace. Ignoring...")
continue

Check warning on line 136 in bitswap/network/httpnet/httpnet.go

View check run for this annotation

Codecov / codecov/patch

bitswap/network/httpnet/httpnet.go#L134-L136

Added lines #L134 - L136 were not covered by tests
}

net.allowlist[h] = struct{}{}
}
}
}

// WithDenylist sets the hostnames that we are prohibited to connect to via
// HTTP.
func WithDenylist(hosts []string) Option {
return func(net *Network) {
log.Infof("HTTP retrieval denylist: %s", strings.Join(hosts, ", "))
net.denylist = make(map[string]struct{})
for _, h := range hosts {
h = strings.TrimSpace(h)
if h == "" {
log.Error("empty string in denylist. Ignoring...")
continue

Check warning on line 154 in bitswap/network/httpnet/httpnet.go

View check run for this annotation

Codecov / codecov/patch

bitswap/network/httpnet/httpnet.go#L153-L154

Added lines #L153 - L154 were not covered by tests
}
if strings.Contains(h, " ") {
log.Errorf("denylist item '%s' contains a whitespace. Ignoring...")
continue

Check warning on line 158 in bitswap/network/httpnet/httpnet.go

View check run for this annotation

Codecov / codecov/patch

bitswap/network/httpnet/httpnet.go#L157-L158

Added lines #L157 - L158 were not covered by tests
}

net.denylist[h] = struct{}{}
}
}
Expand Down