mirror of https://github.com/docker/docs.git
commit
c2d527c9c6
|
|
@ -380,6 +380,7 @@ func createRouter(c *context, enableCors bool) *mux.Router {
|
||||||
"/containers/{name:.*}/json": getContainerJSON,
|
"/containers/{name:.*}/json": getContainerJSON,
|
||||||
"/containers/{name:.*}/top": proxyContainer,
|
"/containers/{name:.*}/top": proxyContainer,
|
||||||
"/containers/{name:.*}/logs": proxyContainer,
|
"/containers/{name:.*}/logs": proxyContainer,
|
||||||
|
"/containers/{name:.*}/stats": proxyContainer,
|
||||||
"/containers/{name:.*}/attach/ws": notImplementedHandler,
|
"/containers/{name:.*}/attach/ws": notImplementedHandler,
|
||||||
"/exec/{execid:.*}/json": proxyContainer,
|
"/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)
|
copyHeader(w.Header(), resp.Header)
|
||||||
w.WriteHeader(resp.StatusCode)
|
w.WriteHeader(resp.StatusCode)
|
||||||
io.Copy(w, resp.Body)
|
io.Copy(NewWriteFlusher(w), resp.Body)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue