Skip to content

Commit

Permalink
优化针对小程序请求的setup_session处理
Browse files Browse the repository at this point in the history
  • Loading branch information
JoneXiong committed May 30, 2020
1 parent a9add3c commit 2604520
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,32 @@ def get_request(self, httprequest):
else:
return HttpRequest(httprequest)
root.get_request = MethodType(get_request, root)


from odoo.http import session_gc

WXAPP_SID = None

def setup_session(self, httprequest):
# recover or create session
session_gc(self.session_store)

sid = httprequest.args.get('session_id')
explicit_session = True
if not sid:
sid = httprequest.headers.get("X-Openerp-Session-Id")
if not sid:
sid = httprequest.cookies.get('session_id')
explicit_session = False
wxapp_flag = 'Referer' in httprequest.headers and 'servicewechat.com' in httprequest.headers['Referer']
global WXAPP_SID
if wxapp_flag and WXAPP_SID:
sid = WXAPP_SID
if sid is None:
httprequest.session = self.session_store.new()
if wxapp_flag:
WXAPP_SID = httprequest.session.sid
else:
httprequest.session = self.session_store.get(sid)
return explicit_session
root.setup_session = MethodType(setup_session, root)

0 comments on commit 2604520

Please sign in to comment.