2014-12-25 43 views
0

我想,当他取了一些用户的会话cookie的js静态文件:得到饼干龙卷风StaticFileHandler

class StaticFileHandler(web.StaticFileHandler): 
    @gen.coroutine 
    def get(self, path): 
     print ('got JS request from %s' % self.request.remote_ip) 
     print ('request.cookies : %s' % self.request.cookies) 
     super(StaticFileHandler, self).get(path) 

然而,饼干总是None,即使我可以在浏览器中看到它有会话cookie集。

我在这里做错了什么?服务这样的静态文件时,是否无法获取cookie?

由于

回答

1

龙卷风文档警告不要重写StaticFileHandler获得方法:http://tornado.readthedocs.org/en/latest/web.html#tornado.web.StaticFileHandler

“的子类应该仅覆盖在本节中讨论的方法;覆盖其它方法是容易出错的重写StaticFileHandler.get是特别是由于与compute_etag和其他方法的紧密耦合而产生问题。“

我会建议您改为尝试重写StaticFileHandler类的get_content方法:

http://tornado.readthedocs.org/en/latest/web.html#tornado.web.StaticFileHandler.get_content

+0

感谢。我并没有真正改变get方法中的任何东西,只需添加两三行逻辑并调用原始get,所以我不明白这可能会带来什么问题。另外,我最终通过将cookie设置为url参数来解决此问题。 – WeaselFox