mirror of
https://github.com/golang/go
synced 2024-11-17 15:04:45 -07:00
cmd/go/internal/web: improve IP check testing on ipv6 env
The existing implementation lacks consideration of running test on a machine which has ipv6 address but no ipv4 address. Use net.IP.IsLoopback and net.IP.IsUnspecified instead of hardcoded addresses. Fixes: #48575
This commit is contained in:
parent
be571a36c7
commit
fc45adbf7b
@ -17,6 +17,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
urlpkg "net/url"
|
||||
"os"
|
||||
@ -84,9 +85,16 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
|
||||
if url.Host == "localhost.localdev" {
|
||||
return nil, fmt.Errorf("no such host localhost.localdev")
|
||||
}
|
||||
if os.Getenv("TESTGONETWORK") == "panic" && !strings.HasPrefix(url.Host, "127.0.0.1") && !strings.HasPrefix(url.Host, "0.0.0.0") {
|
||||
if os.Getenv("TESTGONETWORK") == "panic" {
|
||||
host := url.Host
|
||||
if h, _, err := net.SplitHostPort(url.Host); err == nil && h != "" {
|
||||
host = h
|
||||
}
|
||||
addr := net.ParseIP(host)
|
||||
if addr == nil || (!addr.IsLoopback() && !addr.IsUnspecified()) {
|
||||
panic("use of network: " + url.String())
|
||||
}
|
||||
}
|
||||
|
||||
fetch := func(url *urlpkg.URL) (*urlpkg.URL, *http.Response, error) {
|
||||
// Note: The -v build flag does not mean "print logging information",
|
||||
|
Loading…
Reference in New Issue
Block a user