Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Douglas
erp5
Commits
fa6ceb99
Commit
fa6ceb99
authored
Apr 02, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Balancer Cookie
parent
fd738753
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
product/ERP5Type/patches/CookieCrumbler.py
product/ERP5Type/patches/CookieCrumbler.py
+27
-0
No files found.
product/ERP5Type/patches/CookieCrumbler.py
View file @
fa6ceb99
...
@@ -70,6 +70,31 @@ def getLoginURL(self):
...
@@ -70,6 +70,31 @@ def getLoginURL(self):
CookieCrumbler
.
getLoginURL
=
getLoginURL
CookieCrumbler
.
getLoginURL
=
getLoginURL
def
balancer_cookie_hook
(
ob
,
req
,
resp
):
"""Post publishing traversal hook to automatically (un)set balancer cookie
If authenticated, then cookie is set to use the same zope on next request,
for a better use of caches. Otherwise, if anonymous, expire cookie so that
the balancer redirects us on any zope.
XXX: Because we only have persistent traversal hooks and we don't want to
complicate code with automatic upgrade, this one is implemented by
pluging into CookieCrumbler, although what they are quite unrelated.
"""
balancer_cookie
=
req
.
get
(
'HTTP_X_BALANCER_CURRENT_COOKIE'
)
if
balancer_cookie
:
try
:
path
=
ob
.
aq_parent
.
absolute_url_path
()
except
AttributeError
:
path
=
'/'
if
req
[
'AUTHENTICATED_USER'
].
getUserName
()
==
'Anonymous User'
:
if
balancer_cookie
in
req
.
cookies
:
resp
.
expireCookie
(
balancer_cookie
,
path
=
path
)
else
:
server_id
=
req
[
'HTTP_X_BALANCER_CURRENT_SERVER'
]
if
server_id
!=
req
.
cookies
.
get
(
balancer_cookie
):
resp
.
setCookie
(
balancer_cookie
,
server_id
,
path
=
path
);
def
modifyRequest
(
self
,
req
,
resp
):
def
modifyRequest
(
self
,
req
,
resp
):
"""Copies cookie-supplied credentials to the basic auth fields.
"""Copies cookie-supplied credentials to the basic auth fields.
...
@@ -83,6 +108,8 @@ def modifyRequest(self, req, resp):
...
@@ -83,6 +108,8 @@ def modifyRequest(self, req, resp):
or
req
.
environ
.
has_key
(
'WEBDAV_SOURCE_PORT'
)):
or
req
.
environ
.
has_key
(
'WEBDAV_SOURCE_PORT'
)):
raise
CookieCrumblerDisabled
raise
CookieCrumblerDisabled
req
.
post_traverse
(
balancer_cookie_hook
,
(
self
,
req
,
resp
))
# attempt may contain information about an earlier attempt to
# attempt may contain information about an earlier attempt to
# authenticate using a higher-up cookie crumbler within the
# authenticate using a higher-up cookie crumbler within the
# same request.
# same request.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment