Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
Alexandr Morozov authored on 2014/08/26 01:50:18... | ... |
@@ -105,22 +105,20 @@ func doRequest(req *http.Request, jar http.CookieJar, timeout TimeoutType) (*htt |
105 | 105 |
data, err := ioutil.ReadFile(path.Join(hostDir, f.Name())) |
106 | 106 |
if err != nil { |
107 | 107 |
return nil, nil, err |
108 |
- } else { |
|
109 |
- pool.AppendCertsFromPEM(data) |
|
110 | 108 |
} |
109 |
+ pool.AppendCertsFromPEM(data) |
|
111 | 110 |
} |
112 | 111 |
if strings.HasSuffix(f.Name(), ".cert") { |
113 | 112 |
certName := f.Name() |
114 | 113 |
keyName := certName[:len(certName)-5] + ".key" |
115 | 114 |
if !hasFile(fs, keyName) { |
116 | 115 |
return nil, nil, fmt.Errorf("Missing key %s for certificate %s", keyName, certName) |
117 |
- } else { |
|
118 |
- cert, err := tls.LoadX509KeyPair(path.Join(hostDir, certName), path.Join(hostDir, keyName)) |
|
119 |
- if err != nil { |
|
120 |
- return nil, nil, err |
|
121 |
- } |
|
122 |
- certs = append(certs, &cert) |
|
123 | 116 |
} |
117 |
+ cert, err := tls.LoadX509KeyPair(path.Join(hostDir, certName), path.Join(hostDir, keyName)) |
|
118 |
+ if err != nil { |
|
119 |
+ return nil, nil, err |
|
120 |
+ } |
|
121 |
+ certs = append(certs, &cert) |
|
124 | 122 |
} |
125 | 123 |
if strings.HasSuffix(f.Name(), ".key") { |
126 | 124 |
keyName := f.Name() |
... | ... |
@@ -138,19 +136,13 @@ func doRequest(req *http.Request, jar http.CookieJar, timeout TimeoutType) (*htt |
138 | 138 |
return nil, nil, err |
139 | 139 |
} |
140 | 140 |
return res, client, nil |
141 |
- } else { |
|
142 |
- for i, cert := range certs { |
|
143 |
- client := newClient(jar, pool, cert, timeout) |
|
144 |
- res, err := client.Do(req) |
|
145 |
- if i == len(certs)-1 { |
|
146 |
- // If this is the last cert, always return the result |
|
147 |
- return res, client, err |
|
148 |
- } else { |
|
149 |
- // Otherwise, continue to next cert if 403 or 5xx |
|
150 |
- if err == nil && res.StatusCode != 403 && !(res.StatusCode >= 500 && res.StatusCode < 600) { |
|
151 |
- return res, client, err |
|
152 |
- } |
|
153 |
- } |
|
141 |
+ } |
|
142 |
+ for i, cert := range certs { |
|
143 |
+ client := newClient(jar, pool, cert, timeout) |
|
144 |
+ res, err := client.Do(req) |
|
145 |
+ // If this is the last cert, otherwise, continue to next cert if 403 or 5xx |
|
146 |
+ if i == len(certs)-1 || err == nil && res.StatusCode != 403 && res.StatusCode < 500 { |
|
147 |
+ return res, client, err |
|
154 | 148 |
} |
155 | 149 |
} |
156 | 150 |
|
... | ... |
@@ -198,10 +190,7 @@ func pingRegistryEndpoint(endpoint string) (RegistryInfo, error) { |
198 | 198 |
|
199 | 199 |
standalone := resp.Header.Get("X-Docker-Registry-Standalone") |
200 | 200 |
log.Debugf("Registry standalone header: '%s'", standalone) |
201 |
- // Accepted values are "true" (case-insensitive) and "1". |
|
202 |
- if strings.EqualFold(standalone, "true") || standalone == "1" { |
|
203 |
- info.Standalone = true |
|
204 |
- } else if len(standalone) > 0 { |
|
201 |
+ if !strings.EqualFold(standalone, "true") && standalone != "1" && len(standalone) > 0 { |
|
205 | 202 |
// there is a header set, and it is not "true" or "1", so assume fails |
206 | 203 |
info.Standalone = false |
207 | 204 |
} |
... | ... |
@@ -306,12 +295,12 @@ func AddRequiredHeadersToRedirectedRequests(req *http.Request, via []*http.Reque |
306 | 306 |
if via != nil && via[0] != nil { |
307 | 307 |
if trustedLocation(req) && trustedLocation(via[0]) { |
308 | 308 |
req.Header = via[0].Header |
309 |
- } else { |
|
310 |
- for k, v := range via[0].Header { |
|
311 |
- if k != "Authorization" { |
|
312 |
- for _, vv := range v { |
|
313 |
- req.Header.Add(k, vv) |
|
314 |
- } |
|
309 |
+ return nil |
|
310 |
+ } |
|
311 |
+ for k, v := range via[0].Header { |
|
312 |
+ if k != "Authorization" { |
|
313 |
+ for _, vv := range v { |
|
314 |
+ req.Header.Add(k, vv) |
|
315 | 315 |
} |
316 | 316 |
} |
317 | 317 |
} |