Merge pull request #1829 from jhadvig/proxy_flush

Flush data periodically instead of their buffering
This commit is contained in:
Daniel Smith 2014-10-21 17:01:15 -07:00
commit 91efe51770
3 changed files with 15 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import (
"net/url"
"path"
"strings"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/httplog"
@ -137,6 +138,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
proxyHost: req.URL.Host,
proxyPathPrepend: path.Join(r.prefix, resourceName, id),
}
proxy.FlushInterval = 200 * time.Millisecond
proxy.ServeHTTP(w, newReq)
}

View File

@ -161,6 +161,16 @@ func (rl *respLogger) Write(b []byte) (int, error) {
return rl.w.Write(b)
}
// Flush implements http.Flusher even if the underlying http.Writer doesn't implement it.
// Flush is used for streaming purposes and allows to flush buffered data to the client.
func (rl *respLogger) Flush() {
if flusher, ok := rl.w.(http.Flusher); ok {
flusher.Flush()
} else {
glog.V(2).Infof("Unable to convert %v into http.Flusher", rl.w)
}
}
// WriteHeader implements http.ResponseWriter.
func (rl *respLogger) WriteHeader(status int) {
rl.status = status

View File

@ -212,8 +212,10 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
})
fw := FlushWriter{writer: w}
if flusher, ok := w.(http.Flusher); ok {
if flusher, ok := fw.writer.(http.Flusher); ok {
fw.flusher = flusher
} else {
s.error(w, fmt.Errorf("Unable to convert %v into http.Flusher", fw))
}
w.Header().Set("Transfer-Encoding", "chunked")
w.WriteHeader(http.StatusOK)