Skip to content

Conversation

@clarakosi
Copy link
Member

The filter adds a domain level redirect similar to the one found
in apache for mediawiki to redirect restbase APIs.

Bug: T279588

The filter adds a domain level redirect similar to the one found
in apache for mediawiki to redirect restbase APIs.

Bug: T279588
@clarakosi clarakosi requested a review from Pchelolo May 14, 2021 21:24
x-request-filters:
- path: lib/redirect_filter.js
options:
ar.wikipedia.beta.wmflabs.org: en.wikipedia.beta.wmflabs.org
Copy link
Contributor

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];
Copy link
Contributor

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) => {
Copy link
Contributor

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/);
});
});
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants