-
Notifications
You must be signed in to change notification settings - Fork 135
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
Streaming uploads #131
Comments
Is the reason for reading the whole body before processing the request because we provide access to urlencoded parameters from HTML forms through If yes, I think whether this is necessary can be decide by just looking at the headers. In other words can we optionally deffer body consumption and provide access to the body in the same way as WAI does? (read: if the |
Yes... looking at this, it all needs to be rewritten. I never liked the idea of reading the whole body upfront, it was just a quick hack to get I think This probably means removing Patches welcome... if not, I'll probably get some time to spend on this in about a month. :-P |
Er, getBody will probably have to stay (but change types) so we can keep the body we've read so far around so we can do things like:
(That is, we don't want to throw away chunks that |
@xich I have a version of this almost implemented. I implemented the check and body parsing when need. I kept Anyway expect my version of this in a day or so. |
Or I may have misunderstood. Are you suggesting that if somebody calls |
No what you describe is roughly what I had in mind (I think). Your I think the only thing we can do is document the mutual exclusion in the haddocks for In short, I think that if |
I would assume I see a conflict between What we could do is that all of them "consume" the body. Say once you call any of those, the others will return some indication of |
Maybe an exception in the ActionM monad would be preferable over returning "some indication of empty" (it's a programmer error). |
@sol |
Yes, true. So maybe only raise exceptions if |
this is relevant to issue scotty-web#131 in current implementation it is still usafe to mix body/jsonBody and bodyReader
I just pushed the initial implementation.
|
@edofic Is it actually necessary to "safe chunks"? I would assume that if |
@sol Of course. This is in fact a simpler solution. |
this makes it safe to call body(or something that uses it) and then use bodyReader. Calling bodyReader will cause subsequent calls to body to result in a BodyPartiallyStreamed exception. still a bit rough around the edges and might require some exception handling when working with mvars (bracket). fixes scotty-web#131
I implemented safer The code is a bit hairy though but I find it hard to refactor into smaller nice units. |
this makes it safe to call body(or something that uses it) and then use bodyReader. Calling bodyReader will cause subsequent calls to body to result in a BodyPartiallyStreamed exception. still a bit rough around the edges and might require some exception handling when working with mvars (bracket). fixes scotty-web#131
this is relevant to issue #131 in current implementation it is still usafe to mix body/jsonBody and bodyReader
this makes it safe to call body(or something that uses it) and then use bodyReader. Calling bodyReader will cause subsequent calls to body to result in a BodyPartiallyStreamed exception. still a bit rough around the edges and might require some exception handling when working with mvars (bracket). fixes #131
I believe it is currently impossible to handle streaming uploads with scotty.
Possible use case is to on the fly process data being uploaded while the upload process itself might be long and slow and also produce a big file.
This could with WAI directly by using requestBody that returns chunks of the body as they arive. But scotty consumes whole body before processing the request.
Changing this would also allow for support of responseRaw (see Util.hs) for direct work with the socket.
However the change seems non trivial to me. I see two possible solutions
unsafeInterleaveIO
for actions that consume body before handling the action. This leaves us with the same interface but makes it, well, unsafe.Web.Scotty.Internal.Types.ActionEnv
to holdIO
actions instead of values. We can then wrap those actions with memoizing combinators. This is safer but breaks existing code.I can implement either of these two but would like some feedback first.
The text was updated successfully, but these errors were encountered: