Skip to content

Delay sending http headers according to PEP3333 #320

@ITcarrot

Description

@ITcarrot

When I'm using hypercorn to deploy wsgidav, it raise

RuntimeError("WSGI app did not call start_response")

After inspecting codes from both project, I find out that wsgidav calls start_response when creating the first chunk of response, not when calling the app object. To figure out whose fault is, I check python PEP 3333 – Python Web Server Gateway Interface v1.0.1. It says:

However, the start_response callable must not actually transmit the response headers. Instead, it must store them for the server or gateway to transmit only after the first iteration of the application return value that yields a non-empty bytestring, or upon the application’s first invocation of the write() callable. In other words, response headers must not be sent until there is actual body data available, or until the application’s returned iterable is exhausted. (The only possible exception to this rule is if the response headers explicitly include a Content-Length of zero.)

According to my understanding, hypercorn should do the first iteration of the application before checking whether start_response is called and sending the headers.

I have created a pull request to demonstrate and fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions