1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #9582 from Mic92/tls_interactive_exec

Fix interactive TLS postContainersAttach
This commit is contained in:
Michael Crosby 2014-12-10 10:37:50 -08:00
commit b905f88ee5

View file

@ -65,6 +65,18 @@ func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
return conn, conn, nil return conn, conn, nil
} }
func closeStreams(streams ...interface{}) {
for _, stream := range streams {
if tcpc, ok := stream.(interface {
CloseWrite() error
}); ok {
tcpc.CloseWrite()
} else if closer, ok := stream.(io.Closer); ok {
closer.Close()
}
}
}
// Check to make sure request's Content-Type is application/json // Check to make sure request's Content-Type is application/json
func checkForJson(r *http.Request) error { func checkForJson(r *http.Request) error {
ct := r.Header.Get("Content-Type") ct := r.Header.Get("Content-Type")
@ -871,20 +883,7 @@ func postContainersAttach(eng *engine.Engine, version version.Version, w http.Re
if err != nil { if err != nil {
return err return err
} }
defer func() { defer closeStreams(inStream, outStream)
if tcpc, ok := inStream.(*net.TCPConn); ok {
tcpc.CloseWrite()
} else {
inStream.Close()
}
}()
defer func() {
if tcpc, ok := outStream.(*net.TCPConn); ok {
tcpc.CloseWrite()
} else if closer, ok := outStream.(io.Closer); ok {
closer.Close()
}
}()
var errStream io.Writer var errStream io.Writer
@ -1134,25 +1133,7 @@ func postContainerExecStart(eng *engine.Engine, version version.Version, w http.
if err != nil { if err != nil {
return err return err
} }
defer closeStreams(inStream, outStream)
defer func() {
if cw, ok := inStream.(interface {
CloseWrite() error
}); ok {
cw.CloseWrite()
} else {
inStream.Close()
}
}()
defer func() {
if cw, ok := outStream.(interface {
CloseWrite() error
}); ok {
cw.CloseWrite()
} else if closer, ok := outStream.(io.Closer); ok {
closer.Close()
}
}()
var errStream io.Writer var errStream io.Writer