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

Merged
merged 2 commits into from Jun 29, 2018

Conversation

Projects
None yet
4 participants
@lukasgraf
Member

lukasgraf commented Jun 24, 2018

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 the the same method at the new location.

Fixes #60

@coveralls

This comment has been minimized.

coveralls commented Jun 24, 2018

Coverage Status

Coverage decreased (-0.04%) to 97.713% when pulling ac0f0fe on redirects into 0078eda on master.

@lukasgraf lukasgraf changed the title from WIP: Add support for redirects from plone.app.redirector: to Add support for redirects from plone.app.redirector Jun 25, 2018

@lukasgraf lukasgraf requested review from buchi, erral and tisto Jun 25, 2018

@erral

erral approved these changes Jun 26, 2018 edited

LGTM

@tisto

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.

This comment has been minimized.

@tisto

tisto Jun 27, 2018

Member

Typo: be -> by

This comment has been minimized.

@lukasgraf

lukasgraf Jun 27, 2018

Member

Thanks, updated 👍

@@ -13,4 +13,12 @@
preserveOriginal="true"
/>
<monkey:patch

This comment has been minimized.

@tisto

tisto Jun 27, 2018

Member

@lukasgraf Plone 5.2 will run on WSGI. I have no idea how well this works with WSGI. Any idea @davisagli @jensens @pbauer?

This comment has been minimized.

@lukasgraf

lukasgraf Jun 27, 2018

Member

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

This comment has been minimized.

@tisto

tisto Jun 27, 2018

Member

@lukasgraf ok, cool. Will give it a try with buildout.coredev 5.2 tomorrow.

lukasgraf added some commits Jun 24, 2018

Add support for redirects from plone.app.redirector:
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.
Patch ZPublisher.HTTPResponse.status_codes in a more defensive way:
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
@lukasgraf

This comment has been minimized.

Member

lukasgraf commented Jun 28, 2018

@tisto I updated the patching so it only happens for appropriate versions:

The patch isn't required any more with Zope >= 4.0a1, where the status_codes have been moved to zExceptions >= 3.2 which includes 308.

This will be the case with Plone 5.2, older version do require the patch.

I therefore implemented patching in a more defensive way:

  • only attempt to apply the patch for Zope < 4.0a1
  • the patch function tries to patch more defensively
  • c.monkeypatch will ignore a possible missing original

So WSGI or not, the patch won't be applied for Plone 5.2 anyway.

@tisto

tisto approved these changes Jun 29, 2018

@tisto tisto merged commit 9c6f6db into master Jun 29, 2018

2 of 3 checks passed

coverage/coveralls Coverage decreased (-0.04%) to 97.713%
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@tisto tisto deleted the redirects branch Jun 29, 2018

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