shelf
shelf copied to clipboard
Provide Buffered Request/Response that can be read many times
Could support cost/immutable data. Nice for common responses?
See https://github.com/dart-lang/shelf/issues/9
It could be implemented as a middleware which you could add if you are OK with the memory overhead of buffering the request body. If you add middleware "buffferRequest" then the full body will be read into a memory buffer, and you will have a memory overhead, but all inner handlers would be able to read the body too multiple times which would be very helpful for some scenarios.
Not sure if it's better as a helper vs middleware
As a helper, you opt in for whichever request you need the feature for.
As middleware, it's ALL REQUESTS – which gets expensive.
Actually the suggestion to have it as a middleware was because I thought that would give the ability to opt-in :-). I was thinking, since middleware can be conditionally applied (depending on eg. path, headers etc.), the overhead would only occur if the condition to apply the buffering middleware were fulfilled (and then only for the execution of the inner handlers after the buffering middleware, not during execution of its outer handlers).
A helper would perhaps be simpler, but I am not sure how it would be applied. Say I wanted to call the shelf_proxy middleware twice, which means it will read the request body twice. How would I apply the helper in this case without rewriting shelf_proxy to call the helper itself?
Here's an attempt at a buffering middleware package:
https://github.com/jonaskello/shelf_buffer_request
It re-implements the Request class which means it will break on any changes to the Request class.
Would love to see this natively integrated!
I mean for me (or better said my use case) it doesn't make sense to have all this middleware goodness if you can't possibly read the body of the request
Would love to see some movement on this. I need this for logging requests. Would Request.change()
with no parameters be a good alternative for now until this gets implemented?