소스 검색

Experiments: HTTP streaming render

Manu Mtz-Almeida 10 년 전
부모
커밋
421793bfba
1개의 변경된 파일14개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      context.go

+ 14 - 0
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 *******/
 /************************************/