Skip to Content
Menu
This question has been flagged
2 Replies
12425 Views

How can i set max_age=7200, secure=True, httponly=True in the openerp cookie ?

I have tried to put this attributes as follow:

if hasattr(response, 'set_cookie'):

        response.set_cookie('sid', value=session.sid, max-age=7200, secure=True, httponly=True)

but always the system raise Session Expired Execption.

How can i set these parameters and what is the best way to set it on the NGINX web server or as the way i tried above. ?

Avatar
Discard
Author Best Answer

Thank you @Hardikgiri Goswami for your quick reply of course i have searched about how to set cookie in python using werkzeug lib as follow ( set_cookie(keyvalue=''max_age=Noneexpires=Nonepath='/'domain=None,secure=Nonehttponly=False) )

ref: http://werkzeug.pocoo.org/docs/0.9/wrappers/

 and for more info about werkzeug you can see this link http://werkzeug.pocoo.org/docs/0.9/

what i have done is:

 response.set_cookie('sid', session.sid, max_age=2*3600, expires=int(time.time())+2*3600, httponly=True)

and this works fine.

 

What i want to know exactly which way is the best for setting cookie parameters specially in OPENERP  like what i did using http.py file or using NGINX reverse proxy like the answer mentioned by @rrehbein in this link http://serverfault.com/questions/278319/how-to-rewrite-the-domain-part-of-set-cookie-in-a-nginx-reverse-proxy.

 

To know more and more about cookies review this very helpful links:

http://pymotw.com/2/Cookie/

https://webapp-improved.appspot.com/guide/response.html

http://pydoc.net/Python/wheezy.http/0.1.260/wheezy.http.cookie/

http://werkzeug.pocoo.org/docs/0.9/wrappers/

Avatar
Discard
Best Answer

Hello Mohammed,

I don't know exaclty what is obstacle for you.

But I have seen example of set_cookie in odoo/openerp/http.py line no 1338.

somehting like 

response.set_cookie('session_id', httprequest.session.sid, max_age=90 * 24 * 60 * 60)

and by searching the string "python response.set_cookie" and found the following link might be use full.

http://docs.pylonsproject.org/projects/pyramid/en/1.0-branch/narr/webob.html

and from the js side I have found in core.js line no. 292, which is located in web module found a function of javascript,

Hope this might be helpful to you.

Avatar
Discard