| ... | ... |
@@ -72,12 +72,12 @@ func httpError(w http.ResponseWriter, err error) {
|
| 72 | 72 |
statusCode = http.StatusUnauthorized |
| 73 | 73 |
} else if strings.Contains(err.Error(), "hasn't been activated") {
|
| 74 | 74 |
statusCode = http.StatusForbidden |
| 75 |
- } |
|
| 76 |
- |
|
| 75 |
+ } |
|
| 76 |
+ |
|
| 77 | 77 |
if err != nil {
|
| 78 | 78 |
utils.Errorf("HTTP Error: statusCode=%d %s", statusCode, err.Error())
|
| 79 |
- http.Error(w, err.Error(), statusCode) |
|
| 80 |
- } |
|
| 79 |
+ http.Error(w, err.Error(), statusCode) |
|
| 80 |
+ } |
|
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 | 83 |
func writeJSON(w http.ResponseWriter, code int, v interface{}) error {
|
| ... | ... |
@@ -236,7 +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.Write([]byte{})
|
|
| 239 |
+ wf.Flush() |
|
| 240 | 240 |
if since != 0 {
|
| 241 | 241 |
// If since, send previous events that happened after the timestamp |
| 242 | 242 |
for _, event := range srv.events {
|
| ... | ... |
@@ -616,6 +616,13 @@ func (wf *WriteFlusher) Write(b []byte) (n int, err error) {
|
| 616 | 616 |
return n, err |
| 617 | 617 |
} |
| 618 | 618 |
|
| 619 |
+// Flush the stream immediately. |
|
| 620 |
+func (wf *WriteFlusher) Flush() {
|
|
| 621 |
+ wf.Lock() |
|
| 622 |
+ defer wf.Unlock() |
|
| 623 |
+ wf.flusher.Flush() |
|
| 624 |
+} |
|
| 625 |
+ |
|
| 619 | 626 |
func NewWriteFlusher(w io.Writer) *WriteFlusher {
|
| 620 | 627 |
var flusher http.Flusher |
| 621 | 628 |
if f, ok := w.(http.Flusher); ok {
|