Skip to content

Fix/follow link paging - #337

Open
sjalloq wants to merge 2 commits into
oras-project:mainfrom
sjalloq:fix/follow-link-paging
Open

sjalloq wants to merge 2 commits into
oras-project:mainfrom
sjalloq:fix/follow-link-paging

Conversation

@sjalloq

@sjalloq sjalloq commented Nov 30, 2026

Copy link
Copy Markdown

Fixes #319.

What changes

list_tags, catalog and pull_referrers now follow the Link header that a registry sends when it answers a listing with only one page. Before, the client dropped the header, so the caller got the first page with no sign that the list was incomplete.

  • list_tags and catalog with n as None: the client follows the links and returns the entries of every page.
  • list_tags and catalog with n as Some: one page, as before. n is the page size the caller asked for.
  • pull_referrers: the client follows the links and returns one index with the referrers of every page.

last still means "start after this entry". It goes on the first request only; the requests after it use the URL from the Link header as the registry sent it.

No signature changes and there are no new methods. The blocking client calls the async methods, so it gets the same behaviour.

Why it is done this way

  • A caller that gives no page size is asking for the list. Returning part of it without saying so is the bug. Fixing that inside the existing methods needs no API change.
  • A caller that gives a page size keeps what it has today. Code that uses n to get one page, or to limit the result, is not affected.
  • It follows oras-go. Repository.Tags and Registry.Repositories loop until a response has no Link header, and send last on the first request only. The next URL is read as in parseLink: the first <...> target, resolved against the URL of the page.
  • A link to another origin is an error. The registry controls the header, and the client must not be sent to another host by it. oras-go refuses such a link for the same reason. The error is a SpecViolationError that names the link.

How behaviour differs from main

Run by hand against registry:3.1.2 with its default configuration and 101 repositories. The registry answers GET /v2/_catalog with 100 repositories and Link: </v2/_catalog?last=repo099&n=100>; rel="next".

Call main This branch
catalog(…, None, None) 100 repositories, the last is repo099 101 repositories, the last is repo100
catalog(…, Some(10), None) 10 repositories 10 repositories

Other differences:

  • More requests. A listing without a page size now makes one request per page.
  • A malformed Link header is an error. Before, the header was not read.
  • A registry without paging is not affected. A response without a Link header ends the listing after one request.

Not in this PR

  • A way to walk a large listing page by page. With n set, the caller still cannot see the Link header, and continues with last as before. oras-go's own API is a callback per page; the equivalent here would be a stream of pages. That is the fuller fix and it is new API, so I have left it for a follow-up if you want it. It was option 3 in the issue.
  • A limit on the number of pages. oras-go has one (TagListMaxPages and its siblings), off by default. It needs a new option in ClientConfig.
  • A limit on the size of a page. oras-go reads each page through a 4 MiB limit.

Tests

The first commit adds nine tests in tests/listing_pagination.rs, against a fake registry that records its requests. Six are ignored because they fail on main: relative links for the tag list, an absolute link for the catalog, last on the first request only, a link to another origin, a Link header without a target, and two pages of referrers. Three pass on main and guard what must not change: a page size returns one page for the tag list and for the catalog, and a response without a link ends the listing. The second commit is the fix and enables the six.

To see the failures: cargo test --test listing_pagination -- --include-ignored on the first commit.

…the referrers

A registry can answer a listing with one page and a Link header that
points to the next page. The client drops the header, so the caller gets
the first page only.

Six tests expect the listings to follow the link and are ignored. Three
tests pin what must not change: a request with a page size returns one
page, and a response without a link ends the listing.

Signed-off-by: Shareef Jalloq <shareef@jalloq.co.uk>
…the referrers

A registry can answer a listing with one page and a Link header that
points to the next page. The client dropped the header, so list_tags,
catalog and pull_referrers returned the first page only, with no sign
that the list was incomplete.

list_tags and catalog now follow the links when the caller gives no page
size, and return the entries of every page. With a page size they return
one page, as before. pull_referrers follows the links and returns one
index with the referrers of every page.

The next URL is the first target of the Link header, resolved against the
URL of the page. A link to another origin is an error.

Signed-off-by: Shareef Jalloq <shareef@jalloq.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

catalog returns only the first page of repositories because it drops the Link header

1 participant