1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/api/server/router
Yong Tang e82dcaab52 Use binary frame for websocket attach endpoint
This fix tries to address the issue raised in 28176 where
text frame was used in websocket attach endpoint. In case
the data send out contains non utf8 data, the connection
will be closed in certain browsers, e.g., Safari.

This fix address the issue by change `PayloadType` to `BinaryFrame`.

This fix is tested manually with Safari. The docker daemon is inside a Linux Virtual Machine.

Create a container with:
```
docker run -itd --name websocket busybox sh -c "while true; do echo -e 'he\\xc3\\x28o'; sleep 5; done"
```

Use the following url (172.16.66.128:2375 is the tcp address of the daemon):
```
file:///websocket.html?url=ws://172.16.66.128:2375/v1.25/containers/websocket/attach/ws?logs=1&stderr=1&stdout=1&stream=1&stdin=1
```

and the following html:
```
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Websocket</title>
  <script type="text/javascript">
    function DockerWebSocket() {
      if ("WebSocket" in window) {
        console.log("WebSocket is supported by Browser...")
        // Remove '?url=' prefix
        url = window.location.search.replace(/^(\?url=)/,"");
        console.log("URL ["+url+"]...");
        var ws = new WebSocket(url);
        ws.onopen = function() {
          console.log("Connection is opened...");
        };
        ws.onclose = function() {
          console.log("Connection is closed...");
        };
        ws.onmessage = function (e) {
          if (typeof e.data === "string") {
            alert("WebSocket received text message ["+e.data+"]!")
          } else {
            console.log("Message is received...")
            var blobReader = new FileReader();
            blobReader.onload = function(event) {
              console.log(JSON.stringify(blobReader.result))
            };
            blobReader.readAsText(e.data)
            console.log("Message complete...")
          }
        };
      } else {
        alert("WebSocket is not supported by Browser!");
      }
    }
  </script>
</head>
<body>
  <div>
    <a href="javascript:DockerWebSocket()">Run DockerWebSocket</a>
  </div>
</body>
</html>
```

This fix fixes 28176.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2017-01-31 14:04:32 -08:00
..
build Fix processing of unset build-args during build 2016-12-07 07:41:55 -08:00
checkpoint router: Return explicit error rather than 404 for experimental. 2016-11-17 15:51:47 -08:00
container Use binary frame for websocket attach endpoint 2017-01-31 14:04:32 -08:00
image Generate ImageDeleteResponse from swagger spec. 2017-01-03 11:47:47 -05:00
network Fix incorrect Scope in network ls/inspect with duplicate network names 2017-01-25 09:39:55 -08:00
plugin Implement content addressability for plugins 2016-12-23 13:29:58 -08:00
swarm change minor mistake of spelling 2016-12-20 21:05:19 +08:00
system rename clusterProvider to cluster in router 2016-12-26 20:53:13 +08:00
volume Convert DanglingOnly to Filters for docker image prune 2016-12-02 20:08:49 -08:00
experimental.go router: Return explicit error rather than 404 for experimental. 2016-11-17 15:51:47 -08:00
local.go api/server/router: add Cancellable function 2016-03-25 10:19:23 -07:00
router.go Decouple the "container" router from the actual daemon implementation. 2016-02-08 11:30:57 -05:00