Skip to content

Commit

Permalink
Mark requests with Accept: application/json header as zope.publisher.…
Browse files Browse the repository at this point in the history
…interfaces.http.IJSONRequest requests.
  • Loading branch information
thet committed Jun 4, 2020
1 parent 6a71a30 commit 47b8966
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ https://zope.readthedocs.io/en/2.13/CHANGES.html
4.4.3 (unreleased)
------------------

- Mark requests with ``Accept: application/json`` header as ``zope.publisher.interfaces.http.IJSONRequest`` requests.
- Update dependencies to newest releases.
- Improve solidity of the ``debugError`` method.
(`#829 <https://github.com/zopefoundation/Zope/issues/829>`_)
Expand Down
4 changes: 2 additions & 2 deletions src/ZPublisher/HTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from zope.interface import implementer
from zope.publisher.base import DebugFlags
from zope.publisher.http import splitport
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces.http import IHTTPRequest
from ZPublisher import xmlrpc
from ZPublisher.BaseRequest import BaseRequest
from ZPublisher.BaseRequest import quote
Expand Down Expand Up @@ -109,7 +109,7 @@ class NestedLoopExit(Exception):
pass


@implementer(IBrowserRequest)
@implementer(IHTTPRequest)
class HTTPRequest(BaseRequest):
""" Model HTTP request data.
Expand Down
8 changes: 8 additions & 0 deletions src/ZPublisher/WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
from zope.event import notify
from zope.globalrequest import clearRequest
from zope.globalrequest import setRequest
from zope.interface import alsoProvides
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces.http import IJSONRequest
from zope.publisher.skinnable import setDefaultSkin
from zope.security.management import endInteraction
from zope.security.management import newInteraction
Expand Down Expand Up @@ -349,6 +352,11 @@ def publish_module(environ, start_response,
environ,
new_response))

if environ.get('HTTP_ACCEPT', None) == 'application/json':
alsoProvides(new_request, IJSONRequest)
else:
alsoProvides(new_request, IBrowserRequest)

for i in range(getattr(new_request, 'retry_max_count', 3) + 1):
request = new_request
response = new_response
Expand Down

0 comments on commit 47b8966

Please sign in to comment.