-
Notifications
You must be signed in to change notification settings - Fork 8
Allow access to raw output stream #3
Comments
Would love some way to stream large content and at the moment I can't find a way to do this correctly. I'm not sure what my impl would look like given the |
In general, I'm a big fan of this change. I wonder, though, whether the |
The degenerate implementation of a delayed stream would take a simple byte array. When using let degenerateCase bytes (stream: System.IO.Stream) =
async {
do! stream.WriteAsync(bytes, 0, bytes.Length) |> Async.AwaitIAsyncResult |> Async.Ignore
}
let represent bytes =
{ Data = DelayedStream (degenerateCase bytes)
Description = { … } } Substitute |
@panesofglass Not sure that it would. It could be something that also gets some of the Freya state, but that would complicate the signature when we could just rely on the caller injecting the necessary dependencies through partial application. Once we begin writing to the stream, the status and headers get sent, so all attributes of the response are no longer editable. It doesn't make much sense to expose them here if the consumer can't really use them. |
I don't know if this would be universally true, in my current scenario it is known (but large).
how would this work if params injected are |
@et1975 On content length, we could have DelayedStream take an additional On injections from let handleOk =
freya {
let! method = Freya.Optic.get Request.method_
return
{ Data = DelayedStream (useMethodInOutputStream method)
Description = {…} }
} |
/cc @ajgajg1134 from my own team |
Is the motivation to get memory usage down (eg remove preallocation? eg byte[] seq) or to have the server send more push-like data? (Async<byte[]> seq or some sort of Rx/FRP/Event based system?.) Usually in my mind chunked-encoding looks like Also https://tools.ietf.org/html/rfc2616#section-3.6. Implies that headers MAY be written after the body
This stack overflow has an example of it I think if it's a more event-y (eg Server Sent Events thing) maybe it should be outside of Representation, and use the static overloads to allow handleX to use it. Eg It now takes Freya or Representation. So maybe it can take Freya or the like. That way existing code doesn't break. |
Since we are looking at breaking changes, it would be ideal if it could also resume correctly (support range headers). @neoeinstein would that still fit into |
Currently
Representation
only allows for supplying abyte array
, which is then streamed out over the wire. This means that the byte array must be pre-constructed. This is not always convenient or efficient, especially for larger replies.Proposal: Alter
Representation
by changing the type of theData
field frombyte array
toResponseData
.ResponseData
would be defined as:This will allow for streaming responses, which may mean less memory pressure in the long run. (I see an opportunity for Chiron to be able to stream its data to the wire in this way.)
This would be a breaking change, requiring the addition of the word
Bytes
to existing code that explicitly createsRepresentation
records.The text was updated successfully, but these errors were encountered: