Do multiple reads for WSGI even with content length by anuraaga · Pull Request #37 · connectrpc/connect-python
For .read() methods
https://docs.python.org/3/library/io.html#io.RawIOBase.read
Fewer than size bytes may be returned if the operating system call returns fewer than size bytes.
In practice, all WSGI servers seem to buffer the request to content-length before calling the app...except for pyvoy ;) Incidentally that means pyvoy is able to pass bidi streaming tests with WSGI too. I'm currently debugging an occasional macOS crash which seems envoy-related, but am feeling pretty good about the project.
I also took care to follow the WSGI spec "The application should not attempt to read more data than is specified by the CONTENT_LENGTH variable.". If this text wasn't there, it would be easiest to just call .read() with no parameter.
https://peps.python.org/pep-3333/#input-and-error-streams
I'm interested in adding pyvoy to conformance tests after some more debugging, but without it it's quite challenging to add a regression test for this change. I wanted to separate out the logic change from any testing changes but let me know if I should hold off until having that regression test.