Skip to content

Commit

Permalink
feat/update (#320)
Browse files Browse the repository at this point in the history
* chore: update deps

* feat: update deps, switch out of deprecated APIs, use safe-buffer

* chore: fix badgefury

* fix: 0.10 and 0.12 support
  • Loading branch information
daviddias committed May 23, 2017
1 parent 1cf0aa1 commit 657c20d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion 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)
Expand Down
9 changes: 7 additions & 2 deletions lib/spdy/agent.js
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 || {}))
Expand Down
20 changes: 16 additions & 4 deletions lib/spdy/server.js
Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 || {}))
Expand All @@ -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) {
Expand Down Expand Up @@ -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()

Expand Down
15 changes: 8 additions & 7 deletions 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": {
Expand Down Expand Up @@ -34,17 +34,18 @@
"Jesse Cravens <jesse.cravens@gmail.com>"
],
"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"
Expand Down
9 changes: 7 additions & 2 deletions test/client-test.js
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/fixtures.js
Expand Up @@ -93,4 +93,3 @@ exports.everyConfig = function everyConfig (body) {
})
})
}

7 changes: 6 additions & 1 deletion test/server-test.js
Expand Up @@ -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
Expand Down

0 comments on commit 657c20d

Please sign in to comment.