Преглед на файлове

Make /events API send headers immediately

Go's net/http API does not send headers until the first call to
ResponseWriter.Write().  Ordinarily, this is fine, because in most
cases, responses are returned immediately.  However, for the events
API, nothing is written until some event is sent, which causes
timeouts and/or hangs in some HTTP client APIs, which wait for headers
before returning from the "make request" call.
Dan Hirsch преди 11 години
родител
ревизия
dd9f4524d1
променени са 1 файла, в които са добавени 1 реда и са изтрити 0 реда
  1. 1 0
      api.go

+ 1 - 0
api.go

@@ -236,6 +236,7 @@ func getEvents(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
 	}
 	}
 	w.Header().Set("Content-Type", "application/json")
 	w.Header().Set("Content-Type", "application/json")
 	wf := utils.NewWriteFlusher(w)
 	wf := utils.NewWriteFlusher(w)
+	wf.Write([]byte{})
 	if since != 0 {
 	if since != 0 {
 		// If since, send previous events that happened after the timestamp
 		// If since, send previous events that happened after the timestamp
 		for _, event := range srv.events {
 		for _, event := range srv.events {