Missing pagination headers for Branches endpoint
Summary
The Link, X-Next-Page, X-Page, X-Per-Page, X-Prev-Page, X-Total, and X-Total-Pages pagination headers are intermittently missing in responses from the repository/branches endpoint for repositories with more than 20 branches. Sometimes responses have the headers, sometimes they do not.
This breaks clients that use those headers to know if they need to make multiple requests to get the entire branch list.
Steps to reproduce
- Call "https://gitlab.com/api/v4/projects/278964/repository/branches" endpoint (or any other repository with more than 20 branches) multiple times.
- Some responses will have the pagination headers, some will not.
Example Project
https://gitlab.com/gitlab-org/gitlab
https://gitlab.com/api/v4/projects/278964/repository/branches
What is the current bug behavior?
The pagination headers are missing from some responses.
What is the expected correct behavior?
For requests that require pagination, the pagination headers should always be returned so the client knows to make additional requests.
Relevant logs and/or screenshots
Request:
GET /api/v4/projects/278964/repository/branches HTTP/1.1
Private-Token: [REDACTED]
Host: gitlab.com
Connection: close
Correct response headers:
HTTP/1.1 200 OK
Date: Tue, 18 May 2021 17:39:40 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Cache-Control: max-age=0, private, must-revalidate
Etag: W/"010523fe711f4b29ddb444429dfacc7e"
Link: <https://gitlab.com/api/v4/projects/278964/repository/branches?id=278964&page=2&per_page=20>; rel="next", <https://gitlab.com/api/v4/projects/278964/repository/branches?id=278964&page=1&per_page=20>; rel="first", <https://gitlab.com/api/v4/projects/278964/repository/branches?id=278964&page=369&per_page=20>; rel="last"
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Gitlab-Feature-Category: source_code_management
X-Next-Page: 2
X-Page: 1
X-Per-Page: 20
X-Prev-Page:
X-Request-Id: 01F608ZMNY34QPBVPMV9WKYH1Z
X-Runtime: 0.652903
X-Total: 7374
X-Total-Pages: 369
Strict-Transport-Security: max-age=31536000
Referrer-Policy: strict-origin-when-cross-origin
RateLimit-Observed: 1
RateLimit-Remaining: 1999
RateLimit-Reset: 1621359640
RateLimit-ResetTime: Tue, 18 May 2021 17:40:40 GMT
RateLimit-Limit: 2000
GitLab-LB: fe-10-lb-gprd
GitLab-SV: localhost
CF-Cache-Status: DYNAMIC
cf-request-id: 0a2228ea75000061dcf882e000000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 6516ddbd8bd361dc-YVR
Incorrect response headers:
HTTP/1.1 200 OK
Date: Tue, 18 May 2021 17:39:46 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Cache-Control: max-age=0, private, must-revalidate
Etag: W/"010523fe711f4b29ddb444429dfacc7e"
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Gitlab-Feature-Category: source_code_management
X-Request-Id: 01F608ZTSVBQJ7KGPK4WGMQEFX
X-Runtime: 0.043717
Strict-Transport-Security: max-age=31536000
Referrer-Policy: strict-origin-when-cross-origin
RateLimit-Observed: 2
RateLimit-Remaining: 1998
RateLimit-Reset: 1621359646
RateLimit-ResetTime: Tue, 18 May 2021 17:40:46 GMT
RateLimit-Limit: 2000
GitLab-LB: fe-11-lb-gprd
GitLab-SV: localhost
CF-Cache-Status: DYNAMIC
cf-request-id: 0a222902f0000061dd7a344000000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 6516dde4b9ae61dd-YVR
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)