New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix WSGI middleware not to explode quadratically in the case of a larger body #1329
Fix WSGI middleware not to explode quadratically in the case of a larger body #1329
Conversation
I've just realized this might get superseded by #1303, so judge accordingly. |
Great - thanks! Given that this clearly resolves an open bug, I'd suggest that we get this in and fixed. I can't see any downside to that. The test suite currently has a listing failure. I expect it's unrelated to this pull request(?) but it'll needs resolving first, either way. |
Hi @tomchristie , and thanks for looking at this. |
Rather than using Change from the existing: body = message.get("body", b"")
more_body = message.get("more_body", False)
while more_body:
body_message: HTTPRequestEvent = await receive() # type: ignore[assignment]
body += body_message.get("body", b"")
more_body = body_message.get("more_body", False) to this... body_list = [message.get("body", b"")]
more_body = message.get("more_body", False)
while more_body:
body_message: HTTPRequestEvent = await receive() # type: ignore[assignment]
body_list.append(body_message.get("body", b""))
more_body = body_message.get("more_body", False)
body = b"".join(body_list) That'd probably result in a pull request with a smaller change footprint, right? |
I've actually considered this; but I think it would in general result in higher overhead. Writing to a |
Re-opening given #1303 (comment) Currently blocked on the CI type checking failures. |
Thanks Tom; if this is still of interest, I'll rectify 'em typing problems later in the evening. |
Seems like a good plan to me. (Thanks for your time on this) |
@tomchristie done ✔️ (The CI now passes |
Thanks @vytas7! |
…ger body (encode#1329) * Fix WSGI middleware not to explode quadratically in the case of a larger body. * Clean up more_body and body stream handling, get rid of while-else. * Update body type in `build_environ`'s tests (although they pass regardless...) * Address typing issues.
Fixes #708
NB: the proposed patch changes the type signature of a public utility function (
build_environ()
), however the method in question doesn't seem to be documented as part of any externally available interface. If that's unacceptable, I could add a compatibility check/wrapper for it.