@@ -43,6 +43,7 @@ func TestV2Check(t *testing.T) {
43
43
server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
44
44
called <- struct {}{}
45
45
if strings .HasSuffix (r .URL .Path , "/v2/" ) {
46
+ w .Header ().Set ("Docker-Distribution-API-Version" , "registry/2.0" )
46
47
w .WriteHeader (http .StatusOK )
47
48
return
48
49
}
@@ -73,6 +74,60 @@ func TestV2Check(t *testing.T) {
73
74
<- called
74
75
}
75
76
77
+ func TestV2CheckNoDistributionHeader (t * testing.T ) {
78
+ called := make (chan struct {}, 3 )
79
+ var uri * url.URL
80
+ server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
81
+ called <- struct {}{}
82
+ if strings .HasSuffix (r .URL .Path , "/v2/" ) {
83
+ w .Header ().Set ("Docker-Distribution-API-Version" , "" )
84
+ w .WriteHeader (http .StatusOK )
85
+ return
86
+ }
87
+ w .Header ().Set ("X-Docker-Endpoints" , uri .Host )
88
+
89
+ // Images
90
+ if strings .HasSuffix (r .URL .Path , "/images" ) {
91
+ return
92
+ }
93
+
94
+ // ImageTags
95
+ if strings .HasSuffix (r .URL .Path , "/tags" ) {
96
+ fmt .Fprintln (w , `{"tag1":"image1"}` )
97
+ return
98
+ }
99
+
100
+ // get tag->image id
101
+ if strings .HasSuffix (r .URL .Path , "latest" ) {
102
+ fmt .Fprintln (w , `"image1"` )
103
+ return
104
+ }
105
+
106
+ // get image json
107
+ if strings .HasSuffix (r .URL .Path , "json" ) {
108
+ fmt .Fprintln (w , `{"id":"image1"}` )
109
+ return
110
+ }
111
+ t .Fatalf ("unexpected request: %s %s" , r .Method , r .URL .RequestURI ())
112
+ }))
113
+ uri , _ = url .Parse (server .URL )
114
+ conn , err := NewClient ().Connect (uri .Host , true )
115
+ if err != nil {
116
+ t .Fatal (err )
117
+ }
118
+ tags , err := conn .ImageTags ("foo" , "bar" )
119
+ if err != nil {
120
+ t .Fatal (err )
121
+ }
122
+ if tags ["tag1" ] != "image1" {
123
+ t .Errorf ("unexpected tags: %#v" , tags )
124
+ }
125
+
126
+ <- called
127
+ <- called
128
+ <- called
129
+ }
130
+
76
131
func TestInsecureHTTPS (t * testing.T ) {
77
132
called := make (chan struct {}, 2 )
78
133
var uri * url.URL
0 commit comments