Pagination API is broken on instances with non-default ports

Summary

The returned link entry in HTTP headers of API calls with pagination is wrong if the instance is configured with non-default ports. This makes the API unusable if there are more than one page to fetch.

Steps to reproduce

  • Run instance on a non-default port (e.g. 8443).
  • Call the groups or issues API using curl and check the headers.
$ curl -I --header "PRIVATE-TOKEN: AAAABBBBBCCCCCDDDDEEEEE" "https://secret.host.com:8443/api/v4/groups"
HTTP/1.1 200 Connection established
Connection: close

HTTP/2 200
server: nginx
date: Wed, 17 Apr 2019 14:51:11 GMT
content-type: application/json
content-length: 7282
cache-control: no-cache
link: <https://secret.host.com/api/v4/groups?order_by=name&owned=false&page=2&per_page=20&sort=asc&statistics=false&with_custom_attributes=false>; rel="next", <https://secret.host.com/api/v4/groups?order_by=name&owned=false&page=1&per_page=20&sort=asc&statistics=false&with_custom_attributes=false>; rel="first", <https://secret.host.com/api/v4/groups?order_by=name&owned=false&page=11&per_page=20&sort=asc&statistics=false&with_custom_attributes=false>; rel="last"
vary: Origin
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-next-page: 2
x-page: 1
x-per-page: 20
x-prev-page:
x-request-id: Iy7DWicy2N7
x-runtime: 0.389404
x-total: 218
x-total-pages: 11
strict-transport-security: max-age=31536000

What is the current bug behavior?

API calls of (e.g. python-gitlab) abort when fetching the second pagination page.

What is the expected correct behavior?

The URLs in the HTTP-response header should contain the custom port of the instance.

link: <https://secret.host.com:8443/api/v4/groups?order_by=name&owned=false&page=2&per_page=20&sort=asc&statistics=false&with_custom_attributes=false>; rel="next", <https://secret.host.com:8443/api/v4/groups?order_by=name&owned=false&page=1&per_page=20&sort=asc&statistics=false&with_custom_attributes=false>; rel="first", <https://secret.host.com:8443/api/v4/groups?order_by=name&owned=false&page=11&per_page=20&sort=asc&statistics=false&with_custom_attributes=false>; rel="last"

Possible fixes

I assume that the error is located in lib/api/helpers/pagination.rb. On line 26, it should be ...

uri.port = Gitlab.config.gitlab.port

instead of

uri.port = nil

But I am not sure if this may result in a side-effect. Can someone clarify that?

Assignee Loading
Time tracking Loading