Browse Source

Handle SplitHostPort errors

Alfonso Acosta 2 months ago
parent
commit
acd39bb5d4
1 changed files with 12 additions and 7 deletions
  1. 12
    7
      registry/client_factory.go

+ 12
- 7
registry/client_factory.go View File

@@ -93,16 +93,21 @@ attemptChallenge:
93 93
 }
94 94
 
95 95
 func (f *RemoteClientFactory) ClientFor(repo image.CanonicalName, creds Credentials) (Client, error) {
96
-	repoHost, _, err := net.SplitHostPort(repo.Domain)
97
-	if err != nil {
98
-		return nil, err
96
+	repoHosts := []string{repo.Domain}
97
+	// allow the insecure hosts list to contain hosts with or without the port
98
+	repoHostWithoutPort, _, err := net.SplitHostPort(repo.Domain)
99
+	if err == nil {
100
+		// parsing fails if no port is present
101
+		repoHosts = append(repoHosts, repoHostWithoutPort)
99 102
 	}
100 103
 	insecure := false
104
+insecureCheckLoop:
101 105
 	for _, h := range f.InsecureHosts {
102
-		// allow the insecure hosts list to contain hosts with or without the port
103
-		if repoHost == h || repo.Domain == h {
104
-			insecure = true
105
-			break
106
+		for _, repoHost := range repoHosts {
107
+			if h == repoHost {
108
+				insecure = true
109
+				break insecureCheckLoop
110
+			}
106 111
 		}
107 112
 	}
108 113
 

Loading…
Cancel
Save