Browse Source

Merge pull request #30460 from yongtang/28176-attach-binary-frame-websocket

Use binary frame for websocket attach endpoint
Phil Estes 8 years ago
parent
commit
f0089a85ec
2 changed files with 10 additions and 0 deletions
  1. 7 0
      api/server/router/container/container_routes.go
  2. 3 0
      docs/api/version-history.md

+ 7 - 0
api/server/router/container/container_routes.go

@@ -502,6 +502,8 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons
 	done := make(chan struct{})
 	done := make(chan struct{})
 	started := make(chan struct{})
 	started := make(chan struct{})
 
 
+	version := httputils.VersionFromContext(ctx)
+
 	setupStreams := func() (io.ReadCloser, io.Writer, io.Writer, error) {
 	setupStreams := func() (io.ReadCloser, io.Writer, io.Writer, error) {
 		wsChan := make(chan *websocket.Conn)
 		wsChan := make(chan *websocket.Conn)
 		h := func(conn *websocket.Conn) {
 		h := func(conn *websocket.Conn) {
@@ -516,6 +518,11 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons
 		}()
 		}()
 
 
 		conn := <-wsChan
 		conn := <-wsChan
+		// In case version is higher than 1.26, a binary frame will be sent.
+		// See 28176 for details.
+		if versions.GreaterThanOrEqualTo(version, "1.26") {
+			conn.PayloadType = websocket.BinaryFrame
+		}
 		return conn, conn, conn, nil
 		return conn, conn, conn, nil
 	}
 	}
 
 

+ 3 - 0
docs/api/version-history.md

@@ -17,6 +17,9 @@ keywords: "API, Docker, rcli, REST, documentation"
 
 
 [Docker Engine API v1.26](v1.26/) documentation
 [Docker Engine API v1.26](v1.26/) documentation
 
 
+* `GET /containers/(id or name)/attach/ws` now returns WebSocket in binary frame format for API version >= v1.26,
+  and returns WebSocket in text frame format for API version< v1.26, for the purpose of backward-compatibility.
+
 ## v1.25 API changes
 ## v1.25 API changes
 
 
 [Docker Engine API v1.25](v1.25.md) documentation
 [Docker Engine API v1.25](v1.25.md) documentation