mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
dockerd: force HTTP flush at each write (aka poor man's streaming)
This commit is contained in:
@@ -160,6 +160,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AutoFlush struct {
|
||||||
|
http.ResponseWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *AutoFlush) Write(data []byte) (int, error) {
|
||||||
|
ret, err := w.ResponseWriter.Write(data)
|
||||||
|
if flusher, ok := w.ResponseWriter.(http.Flusher); ok {
|
||||||
|
flusher.Flush()
|
||||||
|
}
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
func (docker *Docker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (docker *Docker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
cmd, args := URLToCall(r.URL)
|
cmd, args := URLToCall(r.URL)
|
||||||
log.Printf("%s\n", strings.Join(append(append([]string{"docker"}, cmd), args...), " "))
|
log.Printf("%s\n", strings.Join(append(append([]string{"docker"}, cmd), args...), " "))
|
||||||
@@ -171,7 +183,7 @@ func (docker *Docker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
if method == nil {
|
if method == nil {
|
||||||
docker.CmdUsage(r.Body, w, cmd)
|
docker.CmdUsage(r.Body, w, cmd)
|
||||||
} else {
|
} else {
|
||||||
err := method(r.Body, w, args...)
|
err := method(r.Body, &AutoFlush{w}, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(w, "Error: %s\n", err)
|
fmt.Fprintf(w, "Error: %s\n", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user