-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix http status of the response #22
Conversation
@ale-rt thanks for creating this Pull Request and help improve Plone! To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass. Whenever you feel that the pull request is ready to be tested, either start all jenkins jobs pull requests by yourself, or simply add a comment in this pull request stating:
With this simple comment all the jobs will be started automatically. Happy hacking! |
@lukasgraf as author of plone/plone.rest#76 what do you think about this? |
@jenkins-plone-org please run jobs |
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.
I certainly approve of the "do NOT switch method" aspect for non-GET requests. 👍 💚
Not quite sure about switching from permanent- to temporary-style redirects (see comment). Would love to hear some more opinions.
news/8.bugfix
Outdated
@@ -0,0 +1 @@ | |||
The http status of the response is changed from 301 (Moved Permanently) to 302 (Found) for GET requests and to 307 (Temporary Redirect) for other request methods because nothing prevents the URL to be reused in the future. [ale-rt] |
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.
I'm not sure whether this shouldn't be considered a breaking change (instead of a bugfix). Sure, one could argue that the existing behavior was incorrect, and now gets fixed. But it also does have some potential of breaking client apps in subtle ways.
@@ -84,7 +84,17 @@ def attempt_redirect(self): | |||
# some analytics programs might use this info to track | |||
if query_string: | |||
url += "?" + query_string | |||
self.request.response.redirect(url, status=301, lock=1) | |||
|
|||
# Answer GET requests with 302 (Found). Every other method will be answered |
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.
As for switching the response type for non-GET to ones that indicate that the client should NOT switch methods, I definitely agree, since I already did that in plone.rest
as you noticed 😉
As for switching from permanent (301, 308) to temporary (302, 307) types of redirects: I do agree with your rationale - Plone doesn't give any guarantees about permanency of the new URL, so it could be reused for something else the next day. So temporary is semantically correct.
But, a side effect of that is, that according to MDN - 301 Moved Permanently, this might possibly lead to detrimental effects in terms of SEO:
A browser redirects to this page but search engines don't update their links to the resource (in 'SEO-speak', it is said that the 'link-juice' is not sent to the new URL).
So, for private intranets this may not matter, but for large public Plone sites with lots of redirects in place this could be a disadvantageous change. But honestly, I'm just not familiar enough with SEO aspects to judge whether this ("link-juice", page-rank, ...) even is relevant today. Just a point to consider.
A separate question is: How should we proceed with the behavior in |
We have had this 301 => 302 patch for years, because it is too easy to cause (even temporarily) unnecessary redirects while refactoring/moving content around, and once browser has got wrong 301 response there’s no way to revert it, and it is hard to debug customer problem where customer’s browser has for 301, but there’s already new content at the same address. |
My two cents: the current possibly wrong permanent redirect is worse than a possibly bad effect on SEO. So I would be in favour of this fix. You may want to fix the |
About the tests I also have another PR pending which is expected to break if this is merged: plone/Products.CMFPlone#3015 About the breaking/feature/bugfix extension for me it is quite the same, we can even call it breaking so that none will complain :). I am more interested in keeping consistency with @lukasgraf If I am not wrong That function can be stripped down in something like def attempt_redirect(self):
new_location = self.get_new_location()
if not new_location:
return False
self.request.response.redirect(url, status=self.get_status(), lock=1)
return True One customization is the one I shamelessly copied here (the part about getting the status) and the other should be this one Theoretically, moving parts of Another possibility is to introduce a new adapter to compute the Anyway before taking care of resolving duplicated code we should resolve end the debate between 302/307 and 301/308. Thank you all for your input :) |
The points made by @datakurre and @mauritsvanrees make sense and are convincing. Instead of being ambivalent, I now fully approve 😉 👍 (of 302/307, so exactly as the PR stands). |
Agreed. I also won't be sad to see the 308 monkey patch go.
Correct. The background for that is that it mimics
Yep. Besides the handling of non-GET requests,
Yeah, I think I'd like that approach the best. Much of the computation logic could be pulled up in a mixin class that could be shared by Test coverage for the redirect handling in
it should be pretty easy to see if it still works. The only issue with this I see is the dependency from |
9826b34
to
717ca99
Compare
As an MVP I just updated the tests. |
@jenkins-plone-org please run jobs |
The http status of the response is changed from 301 (Moved Permanently) to 302 (Found) for GET requests and to 307 (Temporary Redirect) for other request methods because nothing prevents the URL to be reused in the future. This was inspired by plone/plone.rest#76 Refs #8
717ca99
to
22399a6
Compare
@jenkins-plone-org please run jobs |
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.
Approved, and ready for merge.
The title of the PR still has 'WIP' in it, so Work In Progress. To me it seems finished.
@lukasgraf Do you also agree this can be merged now? Or do you want to sync this with a PR in plone.rest?
Once merged, I can make a quick release if needed.
This reminds me to remind you all to use labels and not WIP in title! Reason: So we are able to filter large list of PRs using Githubs label filtering. |
@mauritsvanrees I'm a bit late, but: merging this one works for me 👍 |
The http status of the response is changed from 301 (Moved Permanently)
to 302 (Found) for GET requests and to 307 (Temporary Redirect) for
other request methods because nothing prevents the URL to be reused in
the future.
This was inspired by plone/plone.rest#76