gevent处理HTTP请求头部信息

来源:互联网 发布:昌泰祥淘宝店可信吗 编辑:程序博客网 时间:2024/05/25 12:22

【问题】

用gevent的pywsgi写的web服务器,在处理头部的时候发现无法直接根据头部字段的名称获取。


【思路】

抠了一下源码,pywsgi在处理http请求的时候,会给除了“Content-Type”和“Content-Length”之外的 Header 字段添加一个 “HTTP_” 前缀。 

gevent源码如下所示:

    def _headers(self):        key = None        value = None        for header in self.headers.headers:            if key is not None and header[:1] in " \t":                value += header                continue            if key not in (None, 'CONTENT_TYPE', 'CONTENT_LENGTH'):                yield 'HTTP_' + key, value.strip()  #### here            key, value = header.split(':', 1)            key = key.replace('-', '_').upper()        if key not in (None, 'CONTENT_TYPE', 'CONTENT_LENGTH'):            yield 'HTTP_' + key, value.strip()    #### or here

解决

0 0
原创粉丝点击