Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
@@ -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
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