Repository: websockets/ws
Pull request #1072 (2017-04-06 17:43:59)

Update eslint-config-standard to the latest version 🚀
## Version **10.1.0** of [eslint-config-standard](https://github.com/feross/eslint-config-standard) just got published.

<table>
  <tr>
    <th align=left>
      Dependency
    </td>
    <td>
      eslint-config-standard
    </td>
  </tr>
  <tr>
    <th align=left>
      Current Version
    </td>
    <td>
      10.0.0
    </td>
  </tr>
  <tr>
    <th align=left>
      Type
    </td>
    <td>
      devDependency
    </td>
  </tr>
</table>

The version **10.1.0** is **not covered** by your **current version range**.

Without accepting this pull request your project will work just like it did before. There might be a bunch of new features, fixes and perf improvements that the maintainers worked on for you though.

I recommend you look into these changes and try to get onto the latest version of eslint-config-standard.
Given that you have a decent test suite, a passing build is a strong indicator that you can take advantage of these changes by merging the proposed change into your project. Otherwise this branch is a great starting point for you to work on the update.


---


<details>
<summary>Commits</summary>
<p>The new version differs by 2 commits .</p>
<ul>
<li><a href="https://urls.greenkeeper.io/feross/eslint-config-standard/commit/9b1df3a0c5f338dfaafd33b817f22b385f397b8f"><code>9b1df3a</code></a> <code>10.1.0</code></li>
<li><a href="https://urls.greenkeeper.io/feross/eslint-config-standard/commit/5d9604c83315f9d8af5b07ee33b408c300b92d73"><code>5d9604c</code></a> <code>Force latest versions of peer dependencies</code></li>
</ul>
<p>See the <a href="https://urls.greenkeeper.io/feross/eslint-config-standard/compare/b0caf342f4b9e9cfe317bc0548331f1f75466baa...9b1df3a0c5f338dfaafd33b817f22b385f397b8f">full diff</a>.</p>
</details>

<details>
<summary>Not sure how things should work exactly?</summary>

There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html) and of course you may always [ask my humans](https://github.com/greenkeeperio/greenkeeper/issues/new).
</details>


---


Your [Greenkeeper](https://greenkeeper.io) Bot :palm_tree:



Patch:
diff --git a/doc/ws.md b/doc/ws.md
index 8893edf4..af3b8556 100644
--- a/doc/ws.md
+++ b/doc/ws.md
@@ -51,10 +51,11 @@ if `verifyClient` is provided with two arguments then those are:
 
 
 If `handleProtocols` is not set then the handshake is automatically accepted,
-otherwise the function takes a single argument:
+otherwise the function takes two arguments:
 
 - `protocols` {Array} The list of WebSocket subprotocols indicated by the
   client in the `Sec-WebSocket-Protocol` header.
+- `request` {http.IncomingMessage} The client HTTP GET request.
 
 If returned value is `false` then the handshake is rejected with the HTTP 401
 status code, otherwise the returned value sets the value of the
@@ -100,6 +101,7 @@ Emitted when an error occurs on the underlying server.
 ### Event: 'headers'
 
 - `headers` {Array}
+- `request` {http.IncomingMessage}
 
 Emitted before the response headers are written to the socket as part of the
 handshake. This allows you to inspect/modify the headers before they are sent.
diff --git a/lib/WebSocketServer.js b/lib/WebSocketServer.js
index e78efc1a..bd3ef24e 100644
--- a/lib/WebSocketServer.js
+++ b/lib/WebSocketServer.js
@@ -168,7 +168,7 @@ class WebSocketServer extends EventEmitter {
     // Optionally call external protocol selection handler.
     //
     if (this.options.handleProtocols) {
-      protocol = this.options.handleProtocols(protocol);
+      protocol = this.options.handleProtocols(protocol, req);
       if (protocol === false) return abortConnection(socket, 401);
     } else {
       protocol = protocol[0];
@@ -252,11 +252,11 @@ class WebSocketServer extends EventEmitter {
     //
     // Allow external modification/inspection of handshake headers.
     //
-    this.emit('headers', headers);
+    this.emit('headers', headers, req);
 
     socket.write(headers.concat('', '').join('\r\n'));
 
-    const client = new WebSocket([req, socket, head], {
+    const client = new WebSocket([req, socket, head], null, {
       maxPayload: this.options.maxPayload,
       protocolVersion: version,
       extensions,
diff --git a/package.json b/package.json
index 4b94ab1c..d010bd66 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,7 @@
     "benchmark": "~2.1.2",
     "bufferutil": "~3.0.0",
     "eslint": "~3.19.0",
-    "eslint-config-standard": "~10.0.0",
+    "eslint-config-standard": "~10.1.0",
     "eslint-plugin-import": "~2.2.0",
     "eslint-plugin-node": "~4.2.0",
     "eslint-plugin-promise": "~3.5.0",


Test patch:
diff --git a/test/WebSocketServer.test.js b/test/WebSocketServer.test.js
index 3930592b..6092e328 100644
--- a/test/WebSocketServer.test.js
+++ b/test/WebSocketServer.test.js
@@ -801,7 +801,7 @@ describe('WebSocketServer', function () {
       const wss = new WebSocketServer({ port: ++port }, () => {
         const ws = new WebSocket(`ws://localhost:${port}`, ['prot1', 'prot2']);
 
-        ws.on('open', (client) => {
+        ws.on('open', () => {
           assert.strictEqual(ws.protocol, 'prot1');
           wss.close();
           done();
@@ -810,16 +810,17 @@ describe('WebSocketServer', function () {
     });
 
     it('selects the last protocol via protocol handler', function (done) {
-      const wss = new WebSocketServer({
-        handleProtocols: (ps) => ps[ps.length - 1],
-        port: ++port
-      }, () => {
+      const handleProtocols = (protocols, request) => {
+        assert.ok(request instanceof http.IncomingMessage);
+        assert.strictEqual(request.url, '/');
+        return protocols.pop();
+      };
+      const wss = new WebSocketServer({ handleProtocols, port: ++port }, () => {
         const ws = new WebSocket(`ws://localhost:${port}`, ['prot1', 'prot2']);
 
         ws.on('open', () => {
           assert.strictEqual(ws.protocol, 'prot2');
-          wss.close();
-          done();
+          wss.close(done);
         });
       });
     });
@@ -903,6 +904,24 @@ describe('WebSocketServer', function () {
         done();
       });
     });
+
+    it('emits the `headers` event', function (done) {
+      const wss = new WebSocketServer({ port: ++port }, () => {
+        const ws = new WebSocket(`ws://localhost:${port}`);
+
+        wss.on('headers', (headers, request) => {
+          assert.deepStrictEqual(headers.slice(0, 3), [
+            'HTTP/1.1 101 Switching Protocols',
+            'Upgrade: websocket',
+            'Connection: Upgrade'
+          ]);
+          assert.ok(request instanceof http.IncomingMessage);
+          assert.strictEqual(request.url, '/');
+
+          wss.on('connection', () => wss.close(done));
+        });
+      });
+    });
   });
 
   describe('messaging', function () {