From d6ffbfe04bc6b6370e3aa112e7bdd7183a851a94 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 12 Jan 2015 15:02:18 -0500 Subject: Use referer too as source of transaction IDs This allows us to use apache module that use things like ErrorDocument directives to do internal redirects and still retain the original transaction intact. Signed-off-by: Simo Sorce Reviewed-by: Patrick Uiterwijk --- ipsilon/util/page.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ipsilon/util/page.py') diff --git a/ipsilon/util/page.py b/ipsilon/util/page.py index db1c145..0929961 100644 --- a/ipsilon/util/page.py +++ b/ipsilon/util/page.py @@ -22,9 +22,11 @@ from ipsilon.util.trans import Transaction from urllib import unquote try: from urlparse import urlparse + from urlparse import parse_qs except ImportError: # pylint: disable=no-name-in-module, import-error from urllib.parse import urlparse + from urllib.parse import parse_qs def admin_protect(fn): @@ -123,7 +125,18 @@ class Page(Log): def get_valid_transaction(self, provider, **kwargs): try: - return Transaction(provider, **kwargs) + t = Transaction(provider) + # Try with kwargs first + tid = t.find_tid(kwargs) + if not tid: + # If no TID yet See if we have it in a referer + if 'referer' in cherrypy.request.headers: + r = urlparse(unquote(cherrypy.request.headers['referer'])) + if r.query: + tid = t.find_tid(parse_qs(r.query)) + if not tid: + t.create_tid() + return t except ValueError: msg = 'Transaction expired, or cookies not available' raise cherrypy.HTTPError(401, msg) -- cgit