python / python/cpython

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

Offen
#93,416 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
558

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit Lib/wsgiref/validate.py, insbesondere mit der Beschreibung in der Nähe von Zeile 70 und der in der Nähe von Zeile 417 erwähnten Unsicherheit, und prüfe check_content_type in der Nähe von Zeile 428. Reproduziere das Redirect-Beispiel mit dem Validator und prüfe die relevanten WSGI- oder HTTP-Anforderungen. Erledigt ist die Aufgabe, wenn das Verhalten des Validators und das formulierte Ziel übereinstimmen und eine Regressionstestabdeckung für den gemeldeten Fall vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.