Fix up and return next/prev/first/last Link headers #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description
In this project, the Swift Package Registry Service List Package Releases endpoint proxies the Github API List Repository Tags endpoint.
The Github API List Repository Tags endpoint is a paginated endpoint which uses the
per_page
andpage
URL query arguments to control pagination. The default value forper_page
is 30 and the default forpage
is 1. So by default, you are getting the first 30 tags for a respository.When the current response for this endpoint does not represent the entire set of tags for the respository, this endpoint will add
Link
headers to the response. For example, if the request is for the swift-syntax repository:Then the response is:
So the
Link
headers are saying that the URL for the next page of tags ishttps://api.github.com/repositories/143079594/tags?per_page=30&page=2
and the URL for the last page of tags ishttps://api.github.com/repositories/143079594/tags?per_page=30&page=47
.The problem is that the current implementation of this project does not provide appropriate
next/prev/first/last
Link
headers in the response. So currently, it is essentially only providing the first page of tags in the response.Fix Description
Link
headers. So we use theparse-link-header
module to parse theLink
header in the response headers.next/prev/first/last
Link
URLs in the response, then we pass those on to the client, keeping theper_page
andpage
query parameters, but replacing the host and path of the URL appropriately.per_page
andpage
query parameters on thelistPackages
endpoint. So we parse those out of the URL and pass them along to thefetchTag
function.Testing
Now, with this fix if the request is:
Then the response is:
As you can see the
Link
header now provides these additional sections:So if we then fetch the
next
URL:Then the response is: