func (w *FlushingWriter) Write(data []byte) (written int, err error) {
	w.writeMutex.Lock()
	defer w.writeMutex.Unlock()
	w.wrote = true
	written, err = w.ResponseWriter.Write(data)
	if err != nil {
		return
	}
	if f, ok := w.ResponseWriter.(http.Flusher); ok {
		defer func() {
			if r := recover(); r != nil {
				msg := fmt.Sprintf("Error recovered on flushing writer: %#v", r)
				log.Debugf(msg)
				err = fmt.Errorf(msg)
			}
		}()
		f.Flush()
	}
	return
}
Write writes and flushes the data.
package io
import (
	"bufio"
	"errors"
	"fmt"
	"net"
	"net/http"
	"sync"
	"github.com/tsuru/tsuru/log"
)
type FlushingWriter struct {
	http.ResponseWriter
	wrote      bool
	writeMutex sync.Mutex
}
func (w *FlushingWriter) WriteHeader(code int) {
	w.wrote = true
	w.ResponseWriter.WriteHeader(code)
}