Rationale:
In the light of T359652 it would be useful to have an easy way to declare routes that will redirect to other routes, for convenience and deprecation.
Requirements (step 1):
- When the redirect handler is execute it triggers a redirect with status 308 to the specified target.
- The redirect handler takes the redirect target path from the route file.
- The redirect target is specified by a target key in an object that is located under the redirect key in the route declaration.
- The REST root path is applied to the target path when generating the Location header in the response.
- The Location header should contain a relative URL with a full path (that is, the path starting with "/", but no domain or protocol)
{ "path": "/v1/some/path", "class": "MediaWiki\\Rest\\Handler\\RedirectHandler", "redirect": { "target": "/v1/other/path" } }
Requirements (step 2):
- Parameters are preserved when generating redirects. This includes path and query parameters. Body parameters are handled by the client.
{ "path": "/v1/some/path/{param}", "class": "MediaWiki\\Rest\\Handler\\RedirectHandler", "redirect": { "target": "/v1/other/path/{param}" } }
Requirements (step 3, nice to have):
- It should not be necessary to specify the class explicitly:
{ "path": "/v1/some/path/{param}", "redirect": { "target": "/v1/other/path/{param}" } }
Implementation hints:
- The redirect handler should be MediaWiki\\Rest\\Handler\\RedirectHandler
- In the hadnler's code, the "redirect" structure from the path specification can be accessed using $redirect = $this->getConfig()['redirect'].
- The full target path, including the handler root, can be obtained from $locationPath = $this->router->getRoutePath( $redirect['target'] )
- A redirect response can be generated using $this->responseFactory->createTemporaryRedirect( $locationPath ). The resulting Response object can be returned by the handler's execute() method.