mirror of https://github.com/docker/docs.git
add docker stats support
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
45644d8412
commit
adad1f0f75
|
|
@ -364,6 +364,7 @@ func createRouter(c *context, enableCors bool) *mux.Router {
|
|||
"/containers/{name:.*}/json": getContainerJSON,
|
||||
"/containers/{name:.*}/top": proxyContainer,
|
||||
"/containers/{name:.*}/logs": proxyContainer,
|
||||
"/containers/{name:.*}/stats": proxyContainer,
|
||||
"/containers/{name:.*}/attach/ws": notImplementedHandler,
|
||||
"/exec/{execid:.*}/json": proxyContainer,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
)
|
||||
|
||||
type WriteFlusher struct {
|
||||
sync.Mutex
|
||||
w io.Writer
|
||||
flusher http.Flusher
|
||||
}
|
||||
|
||||
func (wf *WriteFlusher) Write(b []byte) (n int, err error) {
|
||||
wf.Lock()
|
||||
defer wf.Unlock()
|
||||
n, err = wf.w.Write(b)
|
||||
wf.flusher.Flush()
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Flush the stream immediately.
|
||||
func (wf *WriteFlusher) Flush() {
|
||||
wf.Lock()
|
||||
defer wf.Unlock()
|
||||
wf.flusher.Flush()
|
||||
}
|
||||
|
||||
func NewWriteFlusher(w io.Writer) *WriteFlusher {
|
||||
var flusher http.Flusher
|
||||
if f, ok := w.(http.Flusher); ok {
|
||||
flusher = f
|
||||
} else {
|
||||
flusher = &ioutils.NopFlusher{}
|
||||
}
|
||||
return &WriteFlusher{w: w, flusher: flusher}
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ func proxy(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Re
|
|||
|
||||
copyHeader(w.Header(), resp.Header)
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
io.Copy(w, resp.Body)
|
||||
io.Copy(NewWriteFlusher(w), resp.Body)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue