-
Notifications
You must be signed in to change notification settings - Fork 107
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
Redirects on REST API #609
Comments
Note there is a filter in qTranslate called Now i also found this from Jetpack. They actually use this hook! This fix was done in Jetpack 5.3 released on September 05, 2017. So i think some of the issues could be solved with this already, especially #489 and #528. From
|
Mmm ok i start to better see the problem while doing some experiments for Gutenberg. We should definitely avoid any redirection on the REST calls. Let's try to find a robust solution. |
This becomes an issue to fix in priority. I'll come back to it soon. |
These redirections are quite a tricky problem. If you use the "hide default" option (which i use for instance) there is actually a redirection if your front cookie does not match the default language. This should not be done on an API REST call! I think i found a better solution to avoid the redirections but i have now an issue with one case when using explicitly the default language. The REST request cannot be parsed in that case, leading to the 404 error. But now i understand why it fails. The main trick with qTranslate is that it overrides the Examples with Expected behavior with hide default, no redirections allowed: It could be possible to handle |
So i think i found a reasonable solution to prevent these nasty API REST redirects:
I'm quite confident it should work so i'm very tempted to push this to master, also because i want most of people to validate it, but i'll wait a few days giving you the possibility to try it first in this fix branch: https://github.com/qtranslate/qtranslate-xt/tree/fix/rest_no_redirect What's behind?
Also, we might miss very specific REST calls using |
I created a PR so please try it and comment it there. I lock this ticket for now. |
I have now merged this PR into master so more people can validate this! |
Fix released in qTranslate-XT 3.5.3. |
hello,
some tickets have been raised about redirects on REST API calls. Here are the duplicated tickets in this repo: #575, #528, #489, #427. These tickets were created in the original qTranslate-X (not maintained) by @mikaelz @venkatraj @ephor @esiao. Please could some of you check this with qTranslate-XT?
Currently qTranslate-XT redirects some REST calls involving the default language. It's possible to disable the redirects but i'm not completely sure about the right solution. There are quite many combinations to test and maybe it depends on how the API is used. Maybe some issues with Jetpack that were fixed? I don't know.
Anyway i tried the given PRs but it actually went worse :-/
Let's take an example: local site with english and french language, default is french. Here i query a post with a GET. I haven't tested with POST requests yet.
Pre-Path Mode (/lang/...) + hide default
With the original code there is a redirect for the default language.
localhost/wp-json/wp/v2/posts/13498
-> french content OK (default)localhost/fr/wp-json/wp/v2/posts/13498
-> redirect to default url above, french OK.localhost/en/wp-json/wp/v2/posts/13498
-> english content OKIt seems the 2d point is the problem mentioned in the tickets but for this test it's fine so i don't understand the issue yet.
Now if i disable the redirect:
localhost/wp-json/wp/v2/posts/13498
-> french content OK (default)localhost/fr/wp-json/wp/v2/posts/13498
-> error! Page not found 404 :(localhost/en/wp-json/wp/v2/posts/13498
-> english content OKHere the disable introduced a regression :-/
Pre-Path Mode + no hide default
localhost/wp-json/wp/v2/posts/13498
redirects tolocalhost/fr/wp-json/wp/v2/posts/13498
Similar to above but the other way around. Any idea when this redirect would be a problem?
If i disable the redirect this time it works fine, no 404.
Query Mode (?lang=xx)
This mode shouldn't be a problem since there are no redirects. I tried only with hide default language and all worked fine:
localhost/wp-json/wp/v2/posts/13498?lang=en
-> english content OKlocalhost/wp-json/wp/v2/posts/13498?lang=fr
-> french content OK (default)localhost/wp-json/wp/v2/posts/13498
-> no redirect, french content OK.The text was updated successfully, but these errors were encountered: