Browse code

Use request factory for registry ping

Currently when the registry ping is sent, it creates the request directly from http.NewRequest instead of from the http request factory. The request factory adds useful header information such as user agent which is needed by the registry.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)

Derek McGowan authored on 2015/03/17 06:18:33
Showing 1 changed files
... ...
@@ -11,6 +11,7 @@ import (
11 11
 
12 12
 	log "github.com/Sirupsen/logrus"
13 13
 	"github.com/docker/docker/registry/v2"
14
+	"github.com/docker/docker/utils"
14 15
 )
15 16
 
16 17
 // for mocking in unit tests
... ...
@@ -133,24 +134,25 @@ func (e *Endpoint) Path(path string) string {
133 133
 
134 134
 func (e *Endpoint) Ping() (RegistryInfo, error) {
135 135
 	// The ping logic to use is determined by the registry endpoint version.
136
+	factory := HTTPRequestFactory(nil)
136 137
 	switch e.Version {
137 138
 	case APIVersion1:
138
-		return e.pingV1()
139
+		return e.pingV1(factory)
139 140
 	case APIVersion2:
140
-		return e.pingV2()
141
+		return e.pingV2(factory)
141 142
 	}
142 143
 
143 144
 	// APIVersionUnknown
144 145
 	// We should try v2 first...
145 146
 	e.Version = APIVersion2
146
-	regInfo, errV2 := e.pingV2()
147
+	regInfo, errV2 := e.pingV2(factory)
147 148
 	if errV2 == nil {
148 149
 		return regInfo, nil
149 150
 	}
150 151
 
151 152
 	// ... then fallback to v1.
152 153
 	e.Version = APIVersion1
153
-	regInfo, errV1 := e.pingV1()
154
+	regInfo, errV1 := e.pingV1(factory)
154 155
 	if errV1 == nil {
155 156
 		return regInfo, nil
156 157
 	}
... ...
@@ -159,7 +161,7 @@ func (e *Endpoint) Ping() (RegistryInfo, error) {
159 159
 	return RegistryInfo{}, fmt.Errorf("unable to ping registry endpoint %s\nv2 ping attempt failed with error: %s\n v1 ping attempt failed with error: %s", e, errV2, errV1)
160 160
 }
161 161
 
162
-func (e *Endpoint) pingV1() (RegistryInfo, error) {
162
+func (e *Endpoint) pingV1(factory *utils.HTTPRequestFactory) (RegistryInfo, error) {
163 163
 	log.Debugf("attempting v1 ping for registry endpoint %s", e)
164 164
 
165 165
 	if e.String() == IndexServerAddress() {
... ...
@@ -168,7 +170,7 @@ func (e *Endpoint) pingV1() (RegistryInfo, error) {
168 168
 		return RegistryInfo{Standalone: false}, nil
169 169
 	}
170 170
 
171
-	req, err := http.NewRequest("GET", e.Path("_ping"), nil)
171
+	req, err := factory.NewRequest("GET", e.Path("_ping"), nil)
172 172
 	if err != nil {
173 173
 		return RegistryInfo{Standalone: false}, err
174 174
 	}
... ...
@@ -213,10 +215,10 @@ func (e *Endpoint) pingV1() (RegistryInfo, error) {
213 213
 	return info, nil
214 214
 }
215 215
 
216
-func (e *Endpoint) pingV2() (RegistryInfo, error) {
216
+func (e *Endpoint) pingV2(factory *utils.HTTPRequestFactory) (RegistryInfo, error) {
217 217
 	log.Debugf("attempting v2 ping for registry endpoint %s", e)
218 218
 
219
-	req, err := http.NewRequest("GET", e.Path(""), nil)
219
+	req, err := factory.NewRequest("GET", e.Path(""), nil)
220 220
 	if err != nil {
221 221
 		return RegistryInfo{}, err
222 222
 	}