@@ -237,12 +237,6 @@ func (m *manifests) handleTags(resp http.ResponseWriter, req *http.Request) *reg
237237 elem := strings .Split (req .URL .Path , "/" )
238238 elem = elem [1 :]
239239 repo := strings .Join (elem [1 :len (elem )- 2 ], "/" )
240- query := req .URL .Query ()
241- nStr := query .Get ("n" )
242- n := 1000
243- if nStr != "" {
244- n , _ = strconv .Atoi (nStr )
245- }
246240
247241 if req .Method == "GET" {
248242 m .lock .Lock ()
@@ -258,19 +252,37 @@ func (m *manifests) handleTags(resp http.ResponseWriter, req *http.Request) *reg
258252 }
259253
260254 var tags []string
261- countTags := 0
262- // TODO: implement pagination https://github.com/opencontainers/distribution-spec/blob/b505e9cc53ec499edbd9c1be32298388921bb705/detail.md#tags-paginated
263255 for tag := range c {
264- if countTags >= n {
265- break
266- }
267- countTags ++
268256 if ! strings .Contains (tag , "sha256:" ) {
269257 tags = append (tags , tag )
270258 }
271259 }
272260 sort .Strings (tags )
273261
262+ // https://github.com/opencontainers/distribution-spec/blob/b505e9cc53ec499edbd9c1be32298388921bb705/detail.md#tags-paginated
263+ // Offset using last query parameter.
264+ if last := req .URL .Query ().Get ("last" ); last != "" {
265+ for i , t := range tags {
266+ if t > last {
267+ tags = tags [i :]
268+ break
269+ }
270+ }
271+ }
272+
273+ // Limit using n query parameter.
274+ if ns := req .URL .Query ().Get ("n" ); ns != "" {
275+ if n , err := strconv .Atoi (ns ); err != nil {
276+ return & regError {
277+ Status : http .StatusBadRequest ,
278+ Code : "BAD_REQUEST" ,
279+ Message : fmt .Sprintf ("parsing n: %v" , err ),
280+ }
281+ } else if n < len (tags ) {
282+ tags = tags [:n ]
283+ }
284+ }
285+
274286 tagsToList := listTags {
275287 Name : repo ,
276288 Tags : tags ,
0 commit comments