Stream sends a streaming response and returns a boolean indicates "Is client disconnected in middle of stream"
(step func(w io.Writer) bool)
| 1320 | // Stream sends a streaming response and returns a boolean |
| 1321 | // indicates "Is client disconnected in middle of stream" |
| 1322 | func (c *Context) Stream(step func(w io.Writer) bool) bool { |
| 1323 | w := c.Writer |
| 1324 | clientGone := w.CloseNotify() |
| 1325 | for { |
| 1326 | select { |
| 1327 | case <-clientGone: |
| 1328 | return true |
| 1329 | default: |
| 1330 | keepOpen := step(w) |
| 1331 | w.Flush() |
| 1332 | if !keepOpen { |
| 1333 | return false |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | /************************************/ |
| 1340 | /******** CONTENT NEGOTIATION *******/ |