@@ -19,6 +19,7 @@ import (
1919 derr "github.com/docker/docker/errors"
2020 "github.com/docker/docker/pkg/ioutils"
2121 "github.com/docker/docker/pkg/signal"
22+ "github.com/docker/docker/pkg/term"
2223 "github.com/docker/docker/runconfig"
2324 "github.com/docker/docker/utils"
2425 "golang.org/x/net/context"
@@ -420,21 +421,32 @@ func (s *containerRouter) postContainersResize(ctx context.Context, w http.Respo
420421}
421422
422423func (s * containerRouter ) postContainersAttach (ctx context.Context , w http.ResponseWriter , r * http.Request , vars map [string ]string ) error {
423- if err := httputils .ParseForm (r ); err != nil {
424+ err := httputils .ParseForm (r )
425+ if err != nil {
424426 return err
425427 }
426428 containerName := vars ["name" ]
427429
428430 _ , upgrade := r .Header ["Upgrade" ]
429431
432+ keys := []byte {}
433+ detachKeys := r .FormValue ("detachKeys" )
434+ if detachKeys != "" {
435+ keys , err = term .ToBytes (detachKeys )
436+ if err != nil {
437+ logrus .Warnf ("Invalid escape keys provided (%s) using default : ctrl-p ctrl-q" , detachKeys )
438+ }
439+ }
440+
430441 attachWithLogsConfig := & daemon.ContainerAttachWithLogsConfig {
431- Hijacker : w .(http.Hijacker ),
432- Upgrade : upgrade ,
433- UseStdin : httputils .BoolValue (r , "stdin" ),
434- UseStdout : httputils .BoolValue (r , "stdout" ),
435- UseStderr : httputils .BoolValue (r , "stderr" ),
436- Logs : httputils .BoolValue (r , "logs" ),
437- Stream : httputils .BoolValue (r , "stream" ),
442+ Hijacker : w .(http.Hijacker ),
443+ Upgrade : upgrade ,
444+ UseStdin : httputils .BoolValue (r , "stdin" ),
445+ UseStdout : httputils .BoolValue (r , "stdout" ),
446+ UseStderr : httputils .BoolValue (r , "stderr" ),
447+ Logs : httputils .BoolValue (r , "logs" ),
448+ Stream : httputils .BoolValue (r , "stream" ),
449+ DetachKeys : keys ,
438450 }
439451
440452 return s .backend .ContainerAttachWithLogs (containerName , attachWithLogsConfig )
@@ -450,15 +462,26 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons
450462 return derr .ErrorCodeNoSuchContainer .WithArgs (containerName )
451463 }
452464
465+ var keys []byte
466+ var err error
467+ detachKeys := r .FormValue ("detachKeys" )
468+ if detachKeys != "" {
469+ keys , err = term .ToBytes (detachKeys )
470+ if err != nil {
471+ logrus .Warnf ("Invalid escape keys provided (%s) using default : ctrl-p ctrl-q" , detachKeys )
472+ }
473+ }
474+
453475 h := websocket .Handler (func (ws * websocket.Conn ) {
454476 defer ws .Close ()
455477
456478 wsAttachWithLogsConfig := & daemon.ContainerWsAttachWithLogsConfig {
457- InStream : ws ,
458- OutStream : ws ,
459- ErrStream : ws ,
460- Logs : httputils .BoolValue (r , "logs" ),
461- Stream : httputils .BoolValue (r , "stream" ),
479+ InStream : ws ,
480+ OutStream : ws ,
481+ ErrStream : ws ,
482+ Logs : httputils .BoolValue (r , "logs" ),
483+ Stream : httputils .BoolValue (r , "stream" ),
484+ DetachKeys : keys ,
462485 }
463486
464487 if err := s .backend .ContainerWsAttachWithLogs (containerName , wsAttachWithLogsConfig ); err != nil {
0 commit comments