|
@@ -15,7 +15,6 @@ import (
|
|
|
"github.com/docker/docker/api/types/backend"
|
|
|
"github.com/docker/docker/pkg/ioutils"
|
|
|
"github.com/docker/docker/pkg/signal"
|
|
|
- "github.com/docker/docker/pkg/term"
|
|
|
"github.com/docker/engine-api/types"
|
|
|
"github.com/docker/engine-api/types/container"
|
|
|
"github.com/docker/engine-api/types/filters"
|
|
@@ -408,15 +407,7 @@ func (s *containerRouter) postContainersAttach(ctx context.Context, w http.Respo
|
|
|
containerName := vars["name"]
|
|
|
|
|
|
_, upgrade := r.Header["Upgrade"]
|
|
|
-
|
|
|
- keys := []byte{}
|
|
|
detachKeys := r.FormValue("detachKeys")
|
|
|
- if detachKeys != "" {
|
|
|
- keys, err = term.ToBytes(detachKeys)
|
|
|
- if err != nil {
|
|
|
- logrus.Warnf("Invalid escape keys provided (%s) using default : ctrl-p ctrl-q", detachKeys)
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
hijacker, ok := w.(http.Hijacker)
|
|
|
if !ok {
|
|
@@ -452,11 +443,24 @@ func (s *containerRouter) postContainersAttach(ctx context.Context, w http.Respo
|
|
|
UseStderr: httputils.BoolValue(r, "stderr"),
|
|
|
Logs: httputils.BoolValue(r, "logs"),
|
|
|
Stream: httputils.BoolValue(r, "stream"),
|
|
|
- DetachKeys: keys,
|
|
|
+ DetachKeys: detachKeys,
|
|
|
MuxStreams: true,
|
|
|
}
|
|
|
|
|
|
- return s.backend.ContainerAttach(containerName, attachConfig)
|
|
|
+ if err = s.backend.ContainerAttach(containerName, attachConfig); err != nil {
|
|
|
+ logrus.Errorf("Handler for %s %s returned error: %v", r.Method, r.URL.Path, err)
|
|
|
+ // Remember to close stream if error happens
|
|
|
+ conn, _, errHijack := hijacker.Hijack()
|
|
|
+ if errHijack == nil {
|
|
|
+ statusCode := httputils.GetHTTPErrorStatusCode(err)
|
|
|
+ statusText := http.StatusText(statusCode)
|
|
|
+ fmt.Fprintf(conn, "HTTP/1.1 %d %s\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n%s\r\n", statusCode, statusText, err.Error())
|
|
|
+ httputils.CloseStreams(conn)
|
|
|
+ } else {
|
|
|
+ logrus.Errorf("Error Hijacking: %v", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
@@ -465,15 +469,8 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons
|
|
|
}
|
|
|
containerName := vars["name"]
|
|
|
|
|
|
- var keys []byte
|
|
|
var err error
|
|
|
detachKeys := r.FormValue("detachKeys")
|
|
|
- if detachKeys != "" {
|
|
|
- keys, err = term.ToBytes(detachKeys)
|
|
|
- if err != nil {
|
|
|
- logrus.Warnf("Invalid escape keys provided (%s) using default : ctrl-p ctrl-q", detachKeys)
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
started := make(chan struct{})
|
|
@@ -499,7 +496,7 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons
|
|
|
GetStreams: setupStreams,
|
|
|
Logs: httputils.BoolValue(r, "logs"),
|
|
|
Stream: httputils.BoolValue(r, "stream"),
|
|
|
- DetachKeys: keys,
|
|
|
+ DetachKeys: detachKeys,
|
|
|
UseStdin: true,
|
|
|
UseStdout: true,
|
|
|
UseStderr: true,
|