fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

About multiple flushes

Open bhtbed opened this issue 10 years ago • 8 comments

Is there a way to do progressive rendering via multiple flushes?

bhtbed avatar Apr 12 '16 03:04 bhtbed

Or can *fasthttp.Response implement http.Flusher interface?

bhtbed avatar Apr 12 '16 08:04 bhtbed

I don't think so, you can see the code it's open. The Response struct doesn't have any .Flush method as I know... so If you want the Writer then you should check ctx.Response.BodyWriter() note that after handler is finished this object is reseting, so if you want to use it later you can copy it using ctx.Response.BodyWriteTo(awriter io.Writer) or copy the whole response using ctx.Response.CopyTo(destinationResponse *fasthttp.Response)

ghost avatar Apr 12 '16 12:04 ghost

@kataras So this feature will not be added to fasthttp?

bhtbed avatar Apr 13 '16 03:04 bhtbed

fasthttp has it's own methodology to handle these things, it doesn't need manual flush, but I really can't answer you with percision, just wait for a better answer from @valyala who mantains this package. Or just think how you could do that you want to do without Flush, take a closer look at the code I'm sure you will find the solution and when you do post the solution here to be visible to others

ghost avatar Apr 13 '16 03:04 ghost

Is there a way to do progressive rendering via multiple flushes?

Yes - see RequestCtx.SetBodyStreamWriter. See the example for this function for details.

valyala avatar Apr 15 '16 15:04 valyala

Very good valyala, can you add Iris to the readme.md and faq.md as with other frameworks? iris web framework is fasthttp based :rose:

ghost avatar Apr 15 '16 15:04 ghost

@kataras , done.

valyala avatar Apr 15 '16 15:04 valyala

@valyala Thanks you, I appreciate this!, again nice job with fasthttp all things you doing are excelent :)

ghost avatar Apr 15 '16 15:04 ghost