Wait for container to be attached before returning from {re}start request

This commit is contained in:
Bryan Boreham committed 2015-09-01 17:48:22 +01:00
1 parent b712ba1e04
commit 1e2344341d
2 files changed
+80 -2

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
package proxy
import (
"net/http"
)
type startContainerInterceptor struct{ proxy *Proxy }
func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error {
container, err := inspectContainerInPath(i.proxy.client, r.URL.Path)
if err == nil && containerShouldAttach(container) {
i.proxy.createWait(r, container.ID)
}
return err
}
func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error {
defer i.proxy.removeWait(r.Request)
if r.StatusCode < 200 || r.StatusCode >= 300 { // Docker didn't do the start
return nil
}
i.proxy.waitForStart(r.Request)
return nil
}