From 421793bfba9d167438c1ca708b7a2c4670ebe7a8 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Tue, 12 May 2015 15:17:46 +0200 Subject: [PATCH] Experiments: HTTP streaming render --- context.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/context.go b/context.go index 807ad05b..d6531b11 100644 --- a/context.go +++ b/context.go @@ -375,6 +375,20 @@ func (c *Context) File(filepath string) { http.ServeFile(c.Writer, c.Request, filepath) } +func (c *Context) Stream(step func(w http.ResponseWriter)) { + w := c.Writer + clientGone := w.CloseNotify() + for { + select { + case <-clientGone: + return + default: + step(w) + w.Flush() + } + } +} + /************************************/ /******** CONTENT NEGOTIATION *******/ /************************************/