Interrupting a request from within receive in a pure ASGI middleware #2190
AHarmlessPyro
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
receive
function 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.disconnect
might be most relevantBeta Was this translation helpful? Give feedback.
All reactions