-
-
Notifications
You must be signed in to change notification settings - Fork 47
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 file support #15
Comments
it's acceptable, the use case limit to download file , and set a proper header tell browser |
@jivank When |
I think the previous way should work too. Do you have issues with streaming file when you use |
Are you referring to
|
@jivank else:
# TODO stream
ctx.response.setHeader("Content-Length", $contentLength)
await ctx.respond(Http200, "", headers)
var
fileStream = newFutureStream[string]("staticFileResponse")
file = openAsync(filePath, fmRead)
await file.readToStream(fileStream)
while true:
let (hasValue, value) = await fileStream.read
if hasValue:
await ctx.send(value)
else:
break
file.close()
ctx.handled = true |
The old method will use ~900MB of memory for the 600MB file. I think this is because |
@jivank |
close as #16 |
httpbeast could probably benefit from a proc which copies the contents of a file to its fd. There is a POSIX API call for this, if someone wants to implement it I will accept. Please submit issues for these kinds of things if you haven't already. In particular to the Nim repo since I think the future stream implementation needs fixing. |
This comment has been minimized.
This comment has been minimized.
Now |
I am wondering if you will drop support for httpbeast for netkit?
I have a pull request that will stream large files, its a simple change but it won't fix the memory leak with httpbeast. Additionally the content-length is sent twice because it appears httpbeast is loading the body data into its own buffer before sending it, so I corrected this with
when defined
, but the content length shows as 0.On macOS it will serve a 600mb and the executable will use 4.9MB memory afterwards.
Please let me know if you would like me to create a pull request.
context.nim
The text was updated successfully, but these errors were encountered: