Skip to content

Redirect API requests to moved projects

Igor Drozdov requested to merge id-fix-redirects-for-project-api into master

Summary

When a project is moved and being accessed by the old full pathour API returns 404. However, we should redirect the user to the up-to-date link.

This commit:

  • When a request is GET, finds a project and takes redirect routes into account
  • If the specified full path is not equal to the current full path, 301 (Moved permanently) is returned with Location set as a header
  • The Location header contains the new url that specifies id

Test

  • Create a project
  • Move it to another namespace or rename it
  • Access it via API using the old full path http://gdk.test:3000/api/v4/projects/root%2Fold-path or http://gdk.test:3000/api/v4/projects/root%2Fold-path/repository/files/files%2Ffile\?ref\=main
  • 301 status is returned with new location, something like http://gdk.test:3000/api/v4/projects/12 or http://gdk.test:3000/api/v4/projects/12/repository/files/files%2Ffile\?ref\=main
Edited by Igor Drozdov

Merge request reports