Make /events API send headers immediately
| ... | ... |
@@ -236,6 +236,7 @@ func getEvents(srv *Server, version float64, w http.ResponseWriter, r *http.Requ |
| 236 | 236 |
} |
| 237 | 237 |
w.Header().Set("Content-Type", "application/json")
|
| 238 | 238 |
wf := utils.NewWriteFlusher(w) |
| 239 |
+ wf.Flush() |
|
| 239 | 240 |
if since != 0 {
|
| 240 | 241 |
// If since, send previous events that happened after the timestamp |
| 241 | 242 |
for _, event := range srv.events {
|
| ... | ... |
@@ -695,6 +695,13 @@ func (wf *WriteFlusher) Write(b []byte) (n int, err error) {
|
| 695 | 695 |
return n, err |
| 696 | 696 |
} |
| 697 | 697 |
|
| 698 |
+// Flush the stream immediately. |
|
| 699 |
+func (wf *WriteFlusher) Flush() {
|
|
| 700 |
+ wf.Lock() |
|
| 701 |
+ defer wf.Unlock() |
|
| 702 |
+ wf.flusher.Flush() |
|
| 703 |
+} |
|
| 704 |
+ |
|
| 698 | 705 |
func NewWriteFlusher(w io.Writer) *WriteFlusher {
|
| 699 | 706 |
var flusher http.Flusher |
| 700 | 707 |
if f, ok := w.(http.Flusher); ok {
|