我使用的Pylons和与response.set_cookie有问题 [英] I'm using Pylons and having issues with response.set_cookie

查看:126
本文介绍了我使用的Pylons和与response.set_cookie有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为Pylons的版本不同,但我找不到一个简单的方法来告诉我运行的版本。在第一个例子我相当肯定是0.9.7和使用webob设置cookie。此环境将@符号设置为\100。正如你可以看到在其他环境做同样的事情正确设置的值。

I am thinking one of the versions of Pylons is different but I could not find an easy way to tell what versions I was running. In the first example I am fairly certain it is 0.9.7 and up using webob to set the cookie. This environment is setting the @ symbol to \100. As you can see in the other environment doing the exact same thing sets the value properly. Any assistance would be appreciated if you need further information let me know.

Pylons的新版本(我认为)设置的值不正确

Newer version of Pylons (I think) setting the value incorrectly

response.set_cookie('email', 'user@domain.com', max_age=3600)
response.headers
ResponseHeaders([('Content-Type', 'text/html; charset=utf-8'), ('Content-Length','0'),
 ('Pragma', 'no-cache'), ('Cache-Control', 'no-cache'), ('Set-Cookie',
'email="user\\100domain.com"; expires="Fri, 03-Jun-2011 21:07:07 GMT"; Max-Age=3600; Path=/')])

测试环境正常/预期

response.set_cookie('email', 'user@domain.com', max_age=3600)
response.headers
HeaderDict([('Content-Type', 'text/html; charset=utf-8'), ('Content-Length', '0'),
('Pragma', 'no-cache'), ('Cache-Control', 'no-cache'), ('Set-Cookie', 
'email=user@domain.com; expires="Fri, 03-Jun-2011 21:07:35 GMT"; Max-Age=3600; Path=/')])


推荐答案

它是因为较新版本的webob。

Its because of the newer version of webob.

pylons 0.9.7中的webob软件包是〜0.9.8,它不会转义cookie值。

The webob package in pylons 0.9.7 is ~0.9.8, which does not escape cookie values.

在当时和现在之间,webob开始转义值,这导致你的新版本失败。如果你深入到webob代码库(较新版本),这是发生在cookie的serialize()方法,它确保值正确转义。旧版本直接设置这些值,并且在序列化时不会转义。

Somewhere between then and now, webob started escaping the values, which is causing your 'new' version to fail. If you dig into the webob codebase (newer version), this is happening in the serialize() method of Cookie where it ensures that the values are escaped properly. The old version was setting these values directly and was not escaping on serializing.

我有一个类似的设置,在virtualenv中运行0.9.7,所以能够重现这种行为

I have a similar setup with 0.9.7 running in virtualenv, so was able to reproduce this behavior on my system.

至于使用相同版本的方法,他们也应该在请求中取消转义值,所以事情应该很好。

As far as you use methods from same version, they should also be unescaping the values in request so things should be fine.

这篇关于我使用的Pylons和与response.set_cookie有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆