python / python/cpython

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

Aperta
#93,416 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib type-bug
Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da Lib/wsgiref/validate.py, in particolare dalla descrizione vicino alla riga 70, dall’incertezza indicata vicino alla riga 417 e da check_content_type intorno alla riga 428. Riproduci l’esempio di redirect con il validatore e verifica i requisiti WSGI o HTTP pertinenti. Il lavoro è completato quando il comportamento del validatore e l’obiettivo dichiarato coincidono, con una copertura di regressione per il caso segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.