diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index bff9bdc3..759ec18e 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -47,6 +47,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { return err } r.Body.Close() + r.Body = ioutil.NopCloser(bytes.NewReader(body)) container := createContainerRequestBody{} if err := json.Unmarshal(body, &container); err != nil { @@ -72,14 +73,14 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { if err := i.setWeaveDNS(&container, hostname); err != nil { return err } - } - newBody, err := json.Marshal(container) - if err != nil { - return err + newBody, err := json.Marshal(container) + if err != nil { + return err + } + r.Body = ioutil.NopCloser(bytes.NewReader(newBody)) + r.ContentLength = int64(len(newBody)) } - r.Body = ioutil.NopCloser(bytes.NewReader(newBody)) - r.ContentLength = int64(len(newBody)) return nil } diff --git a/proxy/create_exec_interceptor.go b/proxy/create_exec_interceptor.go index 80168c95..b015a55b 100644 --- a/proxy/create_exec_interceptor.go +++ b/proxy/create_exec_interceptor.go @@ -1,6 +1,7 @@ package proxy import ( + "bytes" "encoding/json" "io/ioutil" "net/http" @@ -18,6 +19,7 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { return err } r.Body.Close() + r.Body = ioutil.NopCloser(bytes.NewReader(body)) options := docker.CreateExecOptions{} if err := json.Unmarshal(body, &options); err != nil { @@ -29,20 +31,20 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { return err } - _, hasWeaveWait := container.Volumes["/w"] + if _, hasWeaveWait := container.Volumes["/w"]; !hasWeaveWait { + return nil + } + cidrs, err := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig) if err != nil { Log.Infof("Leaving container %s alone because %s", container.ID, err) - } else if hasWeaveWait { - Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) - options.Cmd = append(weaveWaitEntrypoint, options.Cmd...) + return nil } - if err := marshalRequestBody(r, options); err != nil { - return err - } + Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) + options.Cmd = append(weaveWaitEntrypoint, options.Cmd...) - return nil + return marshalRequestBody(r, options) } func (i *createExecInterceptor) InterceptResponse(r *http.Response) error {