mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
dockerd: force HTTP flush at each write (aka poor man's streaming)
This commit is contained in:
parent
8a28efa655
commit
f90183e957
1 changed files with 13 additions and 1 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue