python / python/cpython

wsgiref validator complaining about no content-type when it is not needed

オープン
#93,416 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/wsgiref/validate.py から始め、特に 70 行付近の説明、417 行付近で示されている不確実性、428 行付近の check_content_type を確認してください。validator を使ってリダイレクトの例を再現し、関連する WSGI または HTTP の要件を確認してください。報告されたケースに対する回帰テストのカバレッジがあり、validator の動作と記載された目的が一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。