wsgiref validator complaining about no content-type when it is not needed
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
描述
Bug report
https://github.com/python/cpython/blob/main/Lib/wsgiref/validate.py#L70 says that it wants to check
- That no Content-Type is given when there is no content
However, the code's behaviour appears not to match that.
The code notes there was uncertainty: https://github.com/python/cpython/blob/main/Lib/wsgiref/validate.py#L417
But more importantly, its behaviour is a contradiction with the stated objective mentioned above, as I interpret this.
I also cannot see where RFC2616 (which has been obsoleted by others, it would seem) mandates that behaviour.
In the following example, there is no content, and the validator complains about no Content-Type:
#!/usr/bin/env python3
from wsgiref.simple_server import make_server
from wsgiref.validate import validator
def wsgi_callable(environ, start_response):
start_response('302 Found', [('Location', 'https://example.com/')])
return [] # same result with None
make_server(host='localhost', port=8080, app=validator(wsgi_callable)).serve_forever()
When I make a request with curl localhost:8080, this error appears:
Traceback (most recent call last):
File "/usr/lib/python3.10/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/usr/lib/python3.10/wsgiref/validate.py", line 181, in lint_app
iterator = application(environ, start_response_wrapper)
File "/home/calimero/test.py", line 7, in wsgi_callable
start_response('302 Found', [('Location', 'https://example.com/')])
File "/usr/lib/python3.10/wsgiref/validate.py", line 172, in start_response_wrapper
check_content_type(status, headers)
File "/usr/lib/python3.10/wsgiref/validate.py", line 428, in check_content_type
assert_(0, "No Content-Type header found in headers (%s)" % headers)
File "/usr/lib/python3.10/wsgiref/validate.py", line 128, in assert_
raise AssertionError(*args)
AssertionError: No Content-Type header found in headers ([('Location', 'https://example.com/')])
Your environment
- CPython version tested on: 3.10.4
- Operating system and architecture: Archlinux x86-64
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Lib/wsgiref/validate.py 开始,重点查看第 70 行附近的描述、第 417 行附近提到的不确定性,以及第 428 行附近的 check_content_type。使用验证器重现重定向示例,并检查相关的 WSGI 或 HTTP 要求。当验证器的行为与所述目标一致,并且针对所报告案例有回归测试覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100