Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use whole IPV6 #50

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions httprate.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ func composedKeyFunc(keyFuncs ...KeyFunc) KeyFunc {
}

// canonicalizeIP returns a form of ip suitable for comparison to other IPs.
// For IPv4 addresses, this is simply the whole string.
// For IPv6 addresses, this is the /64 prefix.
// For IPv4 and IPv6 addresses, this is simply the whole string.
func canonicalizeIP(ip string) string {
isIPv6 := false
// This is how net.ParseIP decides if an address is IPv6
Expand All @@ -164,5 +163,5 @@ func canonicalizeIP(ip string) string {
return ip
}

return ipv6.Mask(net.CIDRMask(64, 128)).String()
return ipv6.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the comment at line :141 pls?

}
8 changes: 4 additions & 4 deletions httprate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ func Test_canonicalizeIP(t *testing.T) {
{
name: "IPv6 test 1",
ip: "2001:DB8::21f:5bff:febf:ce22:8a2e",
want: "2001:db8:0:21f::",
want: "2001:db8:0:21f:5bff:febf:ce22:8a2e",
},
{
name: "IPv6 test 2",
ip: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
want: "2001:db8:85a3::",
want: "2001:db8:85a3::8a2e:370:7334",
},
{
name: "IPv6 test 3",
ip: "fe80::1ff:fe23:4567:890a",
want: "fe80::",
want: "fe80::1ff:fe23:4567:890a",
},
{
name: "IPv6 test 4",
ip: "f:f:f:f:f:f:f:f",
want: "f:f:f:f::",
want: "f:f:f:f:f:f:f:f",
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func TestLimitIP(t *testing.T) {
name: "block-ipv6",
requestsLimit: 1,
windowLength: 2 * time.Second,
reqIp: []string{"2001:DB8::21f:5bff:febf:ce22:1111", "2001:DB8::21f:5bff:febf:ce22:2222", "2002:DB8::21f:5bff:febf:ce22:1111"},
reqIp: []string{"2001:DB8::21f:5bff:febf:ce22:1111", "2001:DB8::21f:5bff:febf:ce22:1111", "2002:DB8::21f:5bff:febf:ce22:1111"},
respCodes: []int{200, 429, 200},
},
}
Expand Down
Loading