Add redirect filter for domain redirects#1292
Add redirect filter for domain redirects#1292clarakosi wants to merge 1 commit intowikimedia:masterfrom
Conversation
The filter adds a domain level redirect similar to the one found in apache for mediawiki to redirect restbase APIs. Bug: T279588
| x-request-filters: | ||
| - path: lib/redirect_filter.js | ||
| options: | ||
| ar.wikipedia.beta.wmflabs.org: en.wikipedia.beta.wmflabs.org |
There was a problem hiding this comment.
Would probably be nice to wrap this into a 'domain_redirects' property - just in case we ever want to add some other type of redirects.
| }; | ||
|
|
||
| module.exports = (hyper, req, next, options) => { | ||
| const redirectSource = req.params.domain || `${req.uri}`.split('/')[1]; |
There was a problem hiding this comment.
If there's no domain, don't do anything.
| @@ -0,0 +1,20 @@ | |||
| 'use strict'; | |||
|
|
|||
| const redirectLocation = (redirectTarget, uri) => { | |||
There was a problem hiding this comment.
This ain't gonna work... The problem is that we will receive the uri as internal to the cluster, e.g. http://restbase.svc.eqiad.wmnet/en.wikipedia.org etc.
So your location will also become internal, and the client that receives this redirect will have no idea what to do.
So we need to generate absolute redirect for external requests, and relative redirects for internal requests. normalize_title_filter.js L73-96 does this properly. Now that we have a need for to generate absolute redirects in 2 places, you can extract some code from normalizeTitleFilter into mwutil and use it here too. not sure what the API should be, something like mwUtil.createAbsoluteRedirect
| assert.deepEqual(res.status, 200); | ||
| assert.checkString(res.headers['content-location'], /en.wikipedia.beta.wmflabs.org/); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Neet a test for internal and external requests.
The filter adds a domain level redirect similar to the one found
in apache for mediawiki to redirect restbase APIs.
Bug: T279588