From 657c20d35906a058199c8b8d721c902ef6cdc4d6 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 22 May 2017 21:54:37 -0400 Subject: [PATCH] feat/update (#320) * chore: update deps * feat: update deps, switch out of deprecated APIs, use safe-buffer * chore: fix badgefury * fix: 0.10 and 0.12 support --- README.md | 2 +- lib/spdy/agent.js | 9 +++++++-- lib/spdy/server.js | 20 ++++++++++++++++---- package.json | 15 ++++++++------- test/client-test.js | 9 +++++++-- test/fixtures.js | 1 - test/server-test.js | 7 ++++++- 7 files changed, 45 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 427102e..50062c0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # SPDY Server for node.js [![Build Status](https://travis-ci.org/spdy-http2/node-spdy.svg?branch=master)](http://travis-ci.org/spdy-http2/node-spdy) -[![NPM version](https://badge.fury.io/js/node-spdy.svg)](http://badge.fury.io/js/node-spdy) +[![NPM version](https://badge.fury.io/js/spdy.svg)](http://badge.fury.io/js/spdy) [![dependencies Status](https://david-dm.org/spdy-http2/node-spdy/status.svg?style=flat-square)](https://david-dm.org/spdy-http2/node-spdy) [![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/) [![Waffle](https://img.shields.io/badge/track-waffle-blue.svg?style=flat-square)](https://waffle.io/spdy-http2/node-spdy) diff --git a/lib/spdy/agent.js b/lib/spdy/agent.js index 4c8634a..8ce934f 100644 --- a/lib/spdy/agent.js +++ b/lib/spdy/agent.js @@ -8,6 +8,11 @@ var util = require('util') var transport = require('spdy-transport') var debug = require('debug')('spdy:client') +// Node.js 0.10 and 0.12 support +Object.assign = process.versions.modules >= 46 + ? Object.assign // eslint-disable-next-line + : util._extend + var EventEmitter = require('events').EventEmitter var spdy = require('../spdy') @@ -98,7 +103,7 @@ proto._connect = function _connect (options, callback) { ] // TODO(indutny): reconnect automatically? - var socket = this.createConnection(util._extend({ + var socket = this.createConnection(Object.assign({ NPNProtocols: protocols, ALPNProtocols: protocols, servername: options.servername || options.host @@ -133,7 +138,7 @@ proto._connect = function _connect (options, callback) { } debug('connected protocol=%j', protocol) - var connection = transport.connection.create(socket, util._extend({ + var connection = transport.connection.create(socket, Object.assign({ protocol: /spdy/.test(protocol) ? 'spdy' : 'http2', isServer: false }, state.options.connection || {})) diff --git a/lib/spdy/server.js b/lib/spdy/server.js index 2acd332..b1993fe 100644 --- a/lib/spdy/server.js +++ b/lib/spdy/server.js @@ -10,6 +10,12 @@ var selectHose = require('select-hose') var transport = require('spdy-transport') var debug = require('debug')('spdy:server') var EventEmitter = require('events').EventEmitter +var Buffer = require('safe-buffer').Buffer + +// Node.js 0.8, 0.10 and 0.12 support +Object.assign = process.versions.modules >= 46 + ? Object.assign // eslint-disable-next-line + : util._extend var spdy = require('../spdy') @@ -44,7 +50,7 @@ proto._init = function _init (base, options, handler) { 'http/1.1', 'http/1.0' ] - var actualOptions = util._extend({ + var actualOptions = Object.assign({ NPNProtocols: protocols, // Future-proof @@ -107,7 +113,7 @@ proto._handleConnection = function _handleConnection (socket, protocol) { socket.setNoDelay(true) - var connection = transport.connection.create(socket, util._extend({ + var connection = transport.connection.create(socket, Object.assign({ protocol: /spdy/.test(protocol) ? 'spdy' : 'http2', isServer: true }, state.options.connection || {})) @@ -131,7 +137,7 @@ proto._handleConnection = function _handleConnection (socket, protocol) { // HTTP2 preface var PREFACE = 'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n' -var PREFACE_BUFFER = new Buffer(PREFACE) +var PREFACE_BUFFER = Buffer.from(PREFACE) function hoseFilter (data, callback) { if (data.length < 1) { @@ -205,11 +211,17 @@ proto._onStream = function _onStream (stream) { this._invokeDefault(socket) + // For v0.8, 0.10 and 0.12 + if (process.versions.modules < 46) { + // eslint-disable-next-line + this.listenerCount = EventEmitter.listenerCount.bind(this) + } + // Add lazy `checkContinue` listener, otherwise `res.writeContinue` will be // called before the response object was patched by us. if (stream.headers.expect !== undefined && /100-continue/i.test(stream.headers.expect) && - EventEmitter.listenerCount(this, 'checkContinue') === 0) { + this.listenerCount('checkContinue') === 0) { this.once('checkContinue', function (req, res) { res.writeContinue() diff --git a/package.json b/package.json index 73ea733..6246d29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spdy", - "version": "3.4.5", + "version": "3.4.6", "description": "Implementation of the SPDY protocol on node.js.", "license": "MIT", "scripts": { @@ -34,17 +34,18 @@ "Jesse Cravens " ], "dependencies": { - "debug": "^2.2.0", - "handle-thing": "^1.2.4", - "http-deceiver": "^1.2.4", + "debug": "^2.6.8", + "handle-thing": "^1.2.5", + "http-deceiver": "^1.2.7", + "safe-buffer": "^5.0.1", "select-hose": "^2.0.0", - "spdy-transport": "^2.0.15" + "spdy-transport": "^2.0.18" }, "devDependencies": { "istanbul": "^0.4.5", - "mocha": "^2.2.x", + "mocha": "^3.4.1", "pre-commit": "^1.2.2", - "standard": "^8.6.0" + "standard": "^10.0.2" }, "engines": [ "node >= 0.7.0" diff --git a/test/client-test.js b/test/client-test.js index d787295..1147a70 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -8,6 +8,11 @@ var util = require('util') var fixtures = require('./fixtures') var spdy = require('../') +// Node.js 0.10 and 0.12 support +Object.assign = process.versions.modules >= 46 + ? Object.assign // eslint-disable-next-line + : util._extend + describe('SPDY Client', function () { describe('regular', function () { fixtures.everyConfig(function (protocol, npn, version, plain) { @@ -18,7 +23,7 @@ describe('SPDY Client', function () { beforeEach(function (done) { hmodule = plain ? http : https - var options = util._extend({ + var options = Object.assign({ spdy: { plain: plain } @@ -165,7 +170,7 @@ describe('SPDY Client', function () { beforeEach(function (done) { hmodule = plain ? http : https - var options = util._extend({ + var options = Object.assign({ spdy: { plain: plain, 'x-forwarded-for': true diff --git a/test/fixtures.js b/test/fixtures.js index 1f322d8..559ecc6 100644 --- a/test/fixtures.js +++ b/test/fixtures.js @@ -93,4 +93,3 @@ exports.everyConfig = function everyConfig (body) { }) }) } - diff --git a/test/server-test.js b/test/server-test.js index 5679b79..ca43633 100644 --- a/test/server-test.js +++ b/test/server-test.js @@ -10,13 +10,18 @@ var util = require('util') var fixtures = require('./fixtures') var spdy = require('../') +// Node.js 0.10 and 0.12 support +Object.assign = process.versions.modules >= 46 + ? Object.assign // eslint-disable-next-line + : util._extend + describe('SPDY Server', function () { fixtures.everyConfig(function (protocol, npn, version, plain) { var server var client beforeEach(function (done) { - server = spdy.createServer(util._extend({ + server = spdy.createServer(Object.assign({ spdy: { 'x-forwarded-for': true, plain: plain