refresh before closing the connection

Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
Xian Chaobo 2015-05-18 04:52:37 -04:00
parent ada8208157
commit 014947daad
2 changed files with 10 additions and 8 deletions

View File

@ -545,12 +545,14 @@ func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Re
r.URL.Path = strings.Replace(r.URL.Path, name, container.Id, 1) r.URL.Path = strings.Replace(r.URL.Path, name, container.Id, 1)
} }
if err := proxy(c.tlsConfig, container.Engine.Addr, w, r); err != nil { cb := func(resp *http.Response) {
httpError(w, err.Error(), http.StatusInternalServerError)
}
// force fresh container // force fresh container
container.Refresh() container.Refresh()
}
if err := proxyAsync(c.tlsConfig, container.Engine.Addr, w, r, cb); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
}
} }
// Proxy a request to the right node // Proxy a request to the right node

View File

@ -81,14 +81,14 @@ func proxyAsync(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *ht
w.WriteHeader(resp.StatusCode) w.WriteHeader(resp.StatusCode)
io.Copy(NewWriteFlusher(w), resp.Body) io.Copy(NewWriteFlusher(w), resp.Body)
// cleanup
resp.Body.Close()
closeIdleConnections(client)
if callback != nil { if callback != nil {
callback(resp) callback(resp)
} }
// cleanup
resp.Body.Close()
closeIdleConnections(client)
return nil return nil
} }