-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support for redirects from plone.app.redirector #76
Conversation
7c956b5
to
350abc4
Compare
765c39e
to
be1fceb
Compare
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.
LGTM
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 always a very well written, well documented and well-tested pull request! I hesitate to merge right now because I would like to figure out the WSGI/Zpublisher issue first (and maybe merge plone.rest(api) into the core first).
README.rst
Outdated
*same* method at the new location. | ||
|
||
In practice, both the Python ``requests`` library a well as Postman seem to | ||
honour this behavior be default. |
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.
Typo: be -> by
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.
Thanks, updated 👍
@@ -13,4 +13,12 @@ | |||
preserveOriginal="true" | |||
/> | |||
|
|||
<monkey:patch |
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.
@lukasgraf Plone 5.2 will run on WSGI. I have no idea how well this works with WSGI. Any idea @davisagli @jensens @pbauer?
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.
@tisto The patch isn't necessary any more for newer versions of ZPublisher
anyway, because the status codes code moved to the zExceptions
module and already include the 308 that we need. The patching function is written in a way where it does nothing in this case.
However, I don't think the patch is even needed for 5.1 anymore - I could verify what exact Plone version is the highest that even needs the patch, and then only patch conditionally using a ZCML condition for the relevant (and confirmed working) Plone versions.
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.
@lukasgraf ok, cool. Will give it a try with buildout.coredev 5.2 tomorrow.
plone.rest will now handle redirects created by ``plone.app.redirector`` pretty much the same way as regular Plone. If a redirect exists for a given URL, a ``GET`` request will be answered with ``301``, and the new location for the resource is indicated in the ``Location`` header. Any other request method than GET (``POST``, ``PATCH``, ...) will be answered with ``308 Permanent Redirect``. This status code instructs the client that it should NOT switch the method, but retry (if desired) the request with the *same* method at the new location.
The patch is only needed for Plone < 5.2 (or Zope < 4.0a1 respectively), and we shouldn't attempt to apply it. This change make sure that: - only attempts to apply the patch for Zope < 4.0a1 - the patch function tries to patch more defensively - c.monkeypatch ignores a possible missing original
@tisto I updated the patching so it only happens for appropriate versions: The patch isn't required any more with This will be the case with Plone 5.2, older version do require the patch. I therefore implemented patching in a more defensive way:
So WSGI or not, the patch won't be applied for Plone 5.2 anyway. |
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
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
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
Branch: refs/heads/master Date: 2020-02-14T18:57:04+01:00 Author: ale-rt (ale-rt) <alessandro.pisa@gmail.com> Commit: plone/plone.app.redirector@22399a6 Fix http status of the response 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 Files changed: A news/8.feature M plone/app/redirector/browser.py M plone/app/redirector/tests/test_view.py Repository: plone.app.redirector Branch: refs/heads/master Date: 2020-02-26T23:04:48+01:00 Author: Jens W. Klein (jensens) <jk@kleinundpartner.at> Commit: plone/plone.app.redirector@2f6da29 Merge pull request #22 from plone/8-http-status Fix http status of the response Files changed: A news/8.feature M plone/app/redirector/browser.py M plone/app/redirector/tests/test_view.py
plone.rest
will now handle redirects created byplone.app.redirector
pretty much the same way as regular Plone.If a redirect exists for a given URL, a
GET
request will be answered with301
, and the new location for the resource is indicated in theLocation
header.Any other request method than GET (
POST
,PATCH
, ...) will be answered with308 Permanent Redirect
. This status code instructs the client that it should NOT switch the method, but retry (if desired) the request the the same method at the new location.Fixes #60