Open pablolagos opened 1 year ago
Hello again, We currently need this functionality and I think it could be beneficial to everyone. Basically, the idea is:
In server
func handle(ctx *fasthttp.RequestCtx) {
// DisableBuffering modifies fasthttp to disable headers and body buffering for this request
ctx.DisableBuffering()
// Write headers
ctx.Response.Header.Set(.....)
ctx.Response.Header.Set(.....)
ctx.Response.Header.Set(.....)
// Write body. Headers will be sent and cannot be modified once the body begins to be dispatched.
// src can be any io.Reader or io.ReaderFrom or any object implementing io.WriteTo
// The process would be unbuffered, well, actually using at most a 32KB buffer
// according to the current io.Copy implementation.
// Ideal for serving large files without storing them on RAM.
io.Copy(ctx, src)
}
It would automatically set the Transfer-Encoding header to "chunked" and chunk the content on the fly.
I can write a PR if you think it makes sense for fasthttp
It could make sense but I'm afraid it will be a lot harder to implement correctly than you think. If you can try to make a PR please do.
Hello everyone. I know this has been asked several times, but it's been a while and there have been many changes in fasthttp.
Is there a way to copy a body directly from the source to the user without having to get it completely in memory?
This involves two aspects: