Interrupting a request from within receive in a pure ASGI middleware #2190
Unanswered
AHarmlessPyro
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I'm trying to make a pure ASGI middleware that needs to analyze the body of a request for certain features (think XSS/CSRF/SQLI kind of stuff), and rejecting the request based on that, along with some response analysis. Now, as far as I understand, it's possible to change the path of a middleware stack if you're in the
__call__function of a middleware (like how the CORS middleware works).But, if I try to do something like that in the
receivefunction when parsing each individual data chunk, that's not exactly possible. Is there any alternative structure that I should be following, or some pattern that's valid here ? Or is it impossible to stop a request once you've called the next middleware from within the__call__function.For reference, here's some reference code for what I'm trying to do:
As far as I can tell, something like a
http.disconnectmight be most relevantBeta Was this translation helpful? Give feedback.
All reactions