Skip to content

api: Return absolute URIs in JSON responses

Ensure that all URIs returned in JSON responses of the Web API are absolute (prefixed with protocol and domains).

That commit consists in:

  • adding a request parameter to our custom django reverse function in order to build an abolute URI before returning it

  • providing the input HTTP requests as parameter to reverse in API endpoints implementation

  • centralizing all enrich functions adding URIs in API responses in the swh.web.api.utils module

  • modifying tests implementation to check all returned URIs are absolute

  • adding some new and missing tests related to these improvements

  • modifying enrich function tests to remove hardcoded data in favor of hypothesis

Regarding the HTML responses of the API (when querying it through a browser), the current behavior remains unchanged: URIs are not displayed as absolute.

Related to #2154 (closed)

Warning: That diff is quite large but it mainly consists of passing a new request parameter to the reverse function. I did not want to handle one endpoint at a time and prefer to process all of them in one pass.


Migrated from D2492 (view on Phabricator)

Merge request reports