Repository navigation
Document start_response parameters in wsgiref functions #127522
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 2, 2024 After looking into PEP 3333, this is expected behavior:
The response_headers argument is a list of (header_name, header_value) tuples. It must be a Python list; i.e. type(response_headers) is ListType, and the server may change its contents in any way it desires. Each header_name must be a valid HTTP header field-name (as defined by RFC 2616, Section 4.2), without a trailing colon or other punctuation.
However it is not that clear in the documentation of the module itself. Instead of trying to fix this and contradict the PEP, I think a documentation update will be the best solution to this issue ("modify" word is not listed in the wsgiref documentation page).
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorydocsDocumentation in the Doc dirDocumentation in the Doc dirand removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 2, 2024 - removedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Dec 2, 2024 I'm not sure it requires a doc update.
start_response, in the example, is a parameter whose type is (albeit not explicitly stated) StartResponse which itself is linked to the PEP-3333.Well.. strictly speaking, it does not say that the
start_responseparameter is of this specific type so we could add this note in the docs.- changed the title
[-]wsgiref.handlers.BaseHandler does not copy passed headers; results in wrong, cached Content-Length[/-][+]Document `start_response` parameters in `wsgiref` functions[/+]on Dec 2, 2024 - added a commit that references this issue
on Feb 24, 2025
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsTodo
Bug report
Bug description:
The example WSGI server in the documentation sets the headers as a list in the simple_app function.
When moving the headers from the function to a global (as these headers might not change), this global array of tuples will be modified by the calls to
start_response. This is because this function creates awsgiref.headers.Headerswith the passed reference of the global variable, instead of using a copy.This results the
Content-Lengthvalue being set once but never updated, resulting in too-short or too-long answers as shown by curl:The solution for this problem would be to peform a shallow copy of the headers list, ideally in the
wsgi.headers.Headersclass so that it does not modify the passed reference but its own copy.CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
start_responseobjects should follow a specific protocol #127525start_responseobjects should follow a specific protocol (GH-127525) #130504start_responseobjects should follow a specific protocol (GH-127525) #130505