diff --git a/lib/parser.js b/lib/parser.js index 82e36f7..d2bd7e8 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -116,7 +116,7 @@ module.exports = { } assert.object(options, 'options'); assert.arrayOfString(options.headers, 'options.headers'); - assert.optionalNumber(options.clockSkew, 'options.clockSkew'); + assert.optionalFinite(options.clockSkew, 'options.clockSkew'); var authzHeaderName = options.authorizationHeaderName || 'authorization'; diff --git a/package.json b/package.json index 340a8c9..adbcf72 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "test": "tap test/*.js" }, "dependencies": { - "assert-plus": "^0.2.0", + "assert-plus": "^1.0.0", "jsprim": "^1.2.2", "sshpk": "^1.7.0" }, diff --git a/test/examples.test.js b/test/examples.test.js index 2d4ce1b..82c1890 100644 --- a/test/examples.test.js +++ b/test/examples.test.js @@ -126,7 +126,7 @@ test('find keys and examples', function (t) { * interface has been pretty stable in practice, with minimal change from * 0.8 through to 4.2. */ -var binding, HTTPParser, kOnHeadersComplete; +var binding, HTTPParser, kOnHeadersComplete, methods; if (process.binding) binding = process.binding('http_parser'); @@ -134,6 +134,10 @@ if (binding) HTTPParser = binding.HTTPParser; if (HTTPParser) kOnHeadersComplete = HTTPParser.kOnHeadersComplete; +if (HTTPParser && HTTPParser.methods) + methods = HTTPParser.methods; +else + methods = ['DELETE', 'GET', 'HEAD', 'POST', 'PUT']; function DummyRequest() { } @@ -148,22 +152,37 @@ function parseHttpRequest(data, cb) { var obj = new DummyRequest(); p[kOnHeadersComplete] = onHeadersComplete; function onHeadersComplete(opts) { - obj.httpVersionMajor = opts.versionMajor; - obj.httpVersionMinor = opts.versionMinor; - obj.httpVersion = opts.versionMajor + '.' + opts.versionMinor; + var versionMajorKey = 'versionMajor'; + var versionMinorKey = 'versionMinor'; + var headersKey = 'headers'; + var urlKey = 'url'; + var methodKey = 'method'; + var upgradeKey = 'upgrade'; + if (!(typeof opts === 'object')) { + opts = [].slice.call(arguments); + versionMajorKey = 0; + versionMinorKey = "1"; + headersKey = "2"; + urlKey = "4"; + methodKey = "3"; + upgradeKey = "7"; + } + obj.httpVersionMajor = opts[versionMajorKey]; + obj.httpVersionMinor = opts[versionMinorKey]; + obj.httpVersion = obj.httpVersionMajor + '.' + obj.httpVersionMinor; - obj.rawHeaders = opts.headers; + obj.rawHeaders = opts[headersKey]; obj.headers = {}; - for (var i = 0; i < opts.headers.length; i += 2) { - var k = opts.headers[i].toLowerCase(); - var v = opts.headers[i+1]; + for (var i = 0; i < obj.rawHeaders.length; i += 2) { + var k = obj.rawHeaders[i].toLowerCase(); + var v = obj.rawHeaders[i+1]; obj.headers[k] = v; } - obj.url = opts.url; - obj.path = opts.url; - obj.method = HTTPParser.methods[opts.method]; - obj.upgrade = opts.upgrade; + obj.url = opts[urlKey]; + obj.path = opts[urlKey]; + obj.method = methods[opts[methodKey]]; + obj.upgrade = opts[upgradeKey]; assert.ok(obj.httpVersion); cb(obj);