Streaming HTTP responses #1181
Labels
area-Core
This affects CC's core (the Lua runtime, APIs, computer internals).
area-CraftOS
This affects CraftOS, or any other Lua portions of the mod.
enhancement
An extension of a feature or a new feature.
The HTTP API currently buffers responses on the Java side, only firing a
http_success
/http_failure
message once the response has been closed. It would be neat if there was an option to open HTTP handles in "streaming" mode, where thehttp_success
event is queued immediately after headers are received. The various read methods would block until the HTTP body is received:The main motivation for this is better support for downloading large (or possibly infinitely long) files without having to load the whole thing into memory. More complex use-cases are still better served by websockets.
Some concerns/comments:
I think the correct API here is that
.read()
is what's responsible for reading from the socket, yielding if there's insufficient data. This is different to the rest of CC's API; rednet and websockets passively send events - all.receive()
is doing is listening to them.This is pretty similar to what CCTweaks's tcp support did, and I wasn't wild about it then. Also haven't looked into how this would be implemented on top of Netty or, indeed, if it's possible!
There's a temptation here to make the Java API only provide streaming sockets, and then pre-process the events in Lua, capturing HTTP handles before they're passed to user code.
It'd definitely simplify implementation on the Java side, but not 100% sure. It's definitely a bit of a departure from CraftOS's current hands-off design :).
The text was updated successfully, but these errors were encountered: