asgi spec violation: headers in scope can be an iterator #2572
Unanswered
devkral
asked this question in
Potential Issue
Replies: 1 comment
-
ah yes before somebody says, hey, the code works. Here an counter-example headers = iter([(1, 1), (2, 2), (3, 3)])
if (1, 1) in headers:
print("works 1")
if (1, 1) in headers:
# oops, this isn't executed anymore because of an exhausted iterator
print("works 2") The code seems to work properly but because of the exhaustion problem it doesn't work reliable. I will introduce an emergency fix for lilya soon. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I changed in an asgi framework the type of the headers in a scope to a special iterator which adheres the ASGI spec, uvicorn started to crash.
Here I will explain in detail what is wrong:
Let's assume headers in scope are a list: then everything works. This is the default. But the scope is mutable by the asgi app.
This means we cannot assume that that headers stay a list. E.g. middleware can replace it with an iterator
When headers aren't a list we have multiple problems:
__contains__
for an iterator producing the headers like stated in specs (lilya). This is what the PR fix asgi spec violation causing crash in lilya #2571 tries to fix.My proposal is to save away the initial headers in scope and check if any of them is the close header. A middleware should not tamper here. I will make a new PR if ok.
Beta Was this translation helpful? Give feedback.
All reactions