Skip to content

Commit

Permalink
Feat/update (#43)
Browse files Browse the repository at this point in the history
* fix: update deps, use safe-buffer, update all of its usage
  • Loading branch information
daviddias committed May 23, 2017
1 parent 0ea5c6d commit 5375ac3
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 64 deletions.
3 changes: 2 additions & 1 deletion lib/spdy-transport/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var util = require('util')
var transport = require('../spdy-transport')
var Buffer = require('safe-buffer').Buffer

var debug = {
server: require('debug')('spdy:connection:server'),
Expand Down Expand Up @@ -589,7 +590,7 @@ Connection.prototype.ping = function ping (callback) {
var state = this._spdyState

// HTTP2 is using 8-byte opaque
var opaque = new Buffer(state.constants.PING_OPAQUE_SIZE)
var opaque = Buffer.alloc(state.constants.PING_OPAQUE_SIZE)
opaque.fill(0)
opaque.writeUInt32BE(state.ping.nextId, opaque.length - 4)
state.ping.nextId += 2
Expand Down
11 changes: 8 additions & 3 deletions lib/spdy-transport/protocol/http2/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ var transport = require('../../../spdy-transport')
var base = transport.protocol.base

var util = require('util')
var Buffer = require('buffer').Buffer
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

exports.PREFACE_SIZE = 24
exports.PREFACE = 'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n'
exports.PREFACE_BUFFER = new Buffer(exports.PREFACE)
exports.PREFACE_BUFFER = Buffer.from(exports.PREFACE)

exports.PING_OPAQUE_SIZE = 8

Expand Down Expand Up @@ -92,5 +97,5 @@ exports.errorByCode = base.utils.reverse(exports.error)
exports.DEFAULT_WINDOW = 64 * 1024 - 1

exports.goaway = exports.error
exports.goawayByCode = util._extend({}, exports.errorByCode)
exports.goawayByCode = Object.assign({}, exports.errorByCode)
exports.goawayByCode[0] = 'OK'
2 changes: 1 addition & 1 deletion lib/spdy-transport/protocol/http2/framer.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Framer.prototype._defaultHeaders = function _defaultHeaders (frame, pairs) {
pairs.push({
name: ':authority',
value: frame.host ||
frame.headers && frame.headers.host ||
(frame.headers && frame.headers.host) ||
base.constants.DEFAULT_HOST
})
}
Expand Down
6 changes: 3 additions & 3 deletions lib/spdy-transport/protocol/spdy/dictionary.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

var Buffer = require('buffer').Buffer
var Buffer = require('safe-buffer').Buffer

var dictionary = {}
module.exports = dictionary

dictionary[2] = new Buffer([
dictionary[2] = Buffer.from([
'optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-',
'languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi',
'f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser',
Expand All @@ -21,7 +21,7 @@ dictionary[2] = new Buffer([
'.1statusversionurl\x00'
].join(''))

dictionary[3] = new Buffer([
dictionary[3] = Buffer.from([
0x00, 0x00, 0x00, 0x07, 0x6f, 0x70, 0x74, 0x69, // ....opti
0x6f, 0x6e, 0x73, 0x00, 0x00, 0x00, 0x04, 0x68, // ons....h
0x65, 0x61, 0x64, 0x00, 0x00, 0x00, 0x04, 0x70, // ead....p
Expand Down
11 changes: 8 additions & 3 deletions lib/spdy-transport/protocol/spdy/framer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ var WriteBuffer = require('wbuf')

var debug = require('debug')('spdy:framer')

// Node.js 0.8, 0.10 and 0.12 support
Object.assign = process.versions.modules >= 46
? Object.assign // eslint-disable-next-line
: util._extend

function Framer (options) {
base.Framer.call(this, options)
}
Expand Down Expand Up @@ -156,7 +161,7 @@ Framer.prototype._synFrame = function _synFrame (frame, callback) {
var version = frame.version || 'HTTP/1.1'
var scheme = frame.scheme || 'https'
var host = frame.host ||
frame.headers && frame.headers.host ||
(frame.headers && frame.headers.host) ||
base.constants.DEFAULT_HOST

if (self.version === 2) {
Expand Down Expand Up @@ -197,7 +202,7 @@ Framer.prototype._synFrame = function _synFrame (frame, callback) {
buf.writeUInt32BE(frame.id & 0x7fffffff)
buf.writeUInt32BE(frame.associated & 0x7fffffff)

var weight = frame.priority && frame.priority.weight ||
var weight = (frame.priority && frame.priority.weight) ||
constants.DEFAULT_WEIGHT

// We only have 3 bits for priority in SPDY, try to fit it into this
Expand Down Expand Up @@ -295,7 +300,7 @@ Framer.prototype.pushFrame = function pushFrame (frame, callback) {
priority: frame.priority,

// Merge everything together, there is no difference in SPDY protocol
headers: util._extend(util._extend({}, frame.headers), frame.response)
headers: Object.assign(Object.assign({}, frame.headers), frame.response)
}, callback)
})
}
Expand Down
12 changes: 9 additions & 3 deletions lib/spdy-transport/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ var transport = require('../spdy-transport')

var assert = require('assert')
var util = require('util')

var debug = {
client: require('debug')('spdy:stream:client'),
server: require('debug')('spdy:stream:server')
}
var Buffer = require('buffer').Buffer
var Buffer = require('safe-buffer').Buffer
var Duplex = require('readable-stream').Duplex

// Node.js 0.8, 0.10 and 0.12 support
Object.assign = process.versions.modules >= 46
? Object.assign // eslint-disable-next-line
: util._extend

function Stream (connection, options) {
Duplex.call(this)

Expand Down Expand Up @@ -586,8 +592,8 @@ Stream.prototype.sendHeaders = function sendHeaders (headers, callback) {

// Request wasn't yet send, coalesce headers
if (!state.sent) {
this.headers = util._extend({}, this.headers)
util._extend(this.headers, headers)
this.headers = Object.assign({}, this.headers)
Object.assign(this.headers, headers)
process.nextTick(function () {
if (callback) {
callback(null)
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
"homepage": "https://github.com/spdy-http2/spdy-transport",
"author": "Fedor Indutny <fedor@indutny.com>",
"dependencies": {
"debug": "^2.2.0",
"debug": "^2.6.8",
"hpack.js": "^2.1.6",
"obuf": "^1.1.0",
"readable-stream": "^2.0.1",
"wbuf": "^1.4.0"
"obuf": "^1.1.1",
"readable-stream": "^2.2.9",
"safe-buffer": "^5.0.1",
"wbuf": "^1.7.2"
},
"devDependencies": {
"async": "^1.2.1",
"async": "^2.4.1",
"istanbul": "^0.4.5",
"mocha": "^2.2.5",
"mocha": "^3.4.1",
"pre-commit": "^1.2.2",
"standard": "^8.6.0",
"stream-pair": "^1.0.0"
"standard": "^10.0.2",
"stream-pair": "^1.0.3"
},
"scripts": {
"lint": "standard",
Expand Down
25 changes: 13 additions & 12 deletions test/both/framer-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */

var assert = require('assert')
var Buffer = require('safe-buffer').Buffer

var transport = require('../../')

Expand Down Expand Up @@ -162,15 +163,15 @@ describe('Framer', function () {
id: 41,
priority: 0,
fin: false,
data: new Buffer('hello')
data: Buffer.from('hello')
}, function (err) {
assert(!err)

expect({
type: 'DATA',
id: 41,
fin: false,
data: new Buffer('hello')
data: Buffer.from('hello')
}, done)
})
})
Expand All @@ -180,15 +181,15 @@ describe('Framer', function () {
id: 41,
priority: 0,
fin: true,
data: new Buffer('hello')
data: Buffer.from('hello')
}, function (err) {
assert(!err)

expect({
type: 'DATA',
id: 41,
fin: true,
data: new Buffer('hello')
data: Buffer.from('hello')
}, done)
})
})
Expand All @@ -198,15 +199,15 @@ describe('Framer', function () {
id: 41,
priority: 0,
fin: false,
data: new Buffer(0)
data: Buffer.alloc(0)
}, function (err) {
assert(!err)

expect({
type: 'DATA',
id: 41,
fin: false,
data: new Buffer(0)
data: Buffer.alloc(0)
}, done)
})
})
Expand All @@ -215,7 +216,7 @@ describe('Framer', function () {
framer.setMaxFrameSize(10)
parser.setMaxFrameSize(10)

var big = new Buffer(32)
var big = Buffer.alloc(32)
big.fill('A')

framer.dataFrame({
Expand Down Expand Up @@ -245,15 +246,15 @@ describe('Framer', function () {
id: 41,
priority: 0,
fin: false,
data: new Buffer('hello')
data: Buffer.from('hello')
}, function (err) {
assert(!err)

expect({
type: 'DATA',
id: 41,
fin: false,
data: new Buffer('hello')
data: Buffer.from('hello')
}, function () {
assert.equal(framer.window.send.current,
parser.window.recv.current)
Expand Down Expand Up @@ -779,16 +780,16 @@ describe('Framer', function () {
describe('PING', function () {
it('should generate regular frame', function (done) {
framer.pingFrame({
opaque: new Buffer([ 1, 2, 3, 4, 5, 6, 7, 8 ]),
opaque: Buffer.from([ 1, 2, 3, 4, 5, 6, 7, 8 ]),
ack: true
}, function (err) {
assert(!err)

expect({
type: 'PING',
opaque: version < 4
? new Buffer([ 5, 6, 7, 8 ])
: new Buffer([ 1, 2, 3, 4, 5, 6, 7, 8 ]),
? Buffer.from([ 5, 6, 7, 8 ])
: Buffer.from([ 1, 2, 3, 4, 5, 6, 7, 8 ]),
ack: true
}, done)
})
Expand Down
3 changes: 2 additions & 1 deletion test/both/transport/connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var assert = require('assert')
var async = require('async')
var streamPair = require('stream-pair')
var fixtures = require('./fixtures')
var Buffer = require('safe-buffer').Buffer

var expectData = fixtures.expectData
var everyProtocol = fixtures.everyProtocol
Expand Down Expand Up @@ -358,7 +359,7 @@ describe('Transport/Connection', function () {
id: stream.id,
priority: stream._spdyState.priority.getPriority(),
fin: true,
data: new Buffer(32000)
data: Buffer.alloc(32000)
})
})
})
Expand Down
11 changes: 6 additions & 5 deletions test/both/transport/stream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var assert = require('assert')
var fixtures = require('./fixtures')
var Buffer = require('safe-buffer').Buffer

var expectData = fixtures.expectData
var everyProtocol = fixtures.everyProtocol
Expand Down Expand Up @@ -222,7 +223,7 @@ describe('Transport/Stream', function () {
id: stream.id,
priority: 0,
fin: false,
data: new Buffer('no way')
data: Buffer.from('no way')
})
})

Expand All @@ -244,7 +245,7 @@ describe('Transport/Stream', function () {
})

it('should truncate data to fit maxChunk', function (done) {
var big = new Buffer(1024)
var big = Buffer.alloc(1024)
big.fill('a')

client.request({
Expand All @@ -269,9 +270,9 @@ describe('Transport/Stream', function () {
})

it('should control the flow of the request', function (done) {
var a = new Buffer(128)
var a = Buffer.alloc(128)
a.fill('a')
var b = new Buffer(128)
var b = Buffer.alloc(128)
b.fill('b')

client.request({
Expand Down Expand Up @@ -327,7 +328,7 @@ describe('Transport/Stream', function () {
})

it('should split the data if it is too big', function (done) {
var a = new Buffer(1024)
var a = Buffer.alloc(1024)
a.fill('a')

client.request({
Expand Down
Loading

0 comments on commit 5375ac3

Please sign in to comment.