-
Notifications
You must be signed in to change notification settings - Fork 79
Add redirect filter for domain redirects #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The filter adds a domain level redirect similar to the one found in apache for mediawiki to redirect restbase APIs. Bug: T279588
@@ -197,6 +197,9 @@ spec_root: &spec_root | |||
title: "The RESTBase root" | |||
# Some more general RESTBase info | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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