Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi

Package Overview
Dependencies
Maintainers
2
Versions
295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi - npm Package Compare versions

Comparing version 0.8.3 to 0.8.4

test/integration/multipartParser.js

2

docs/ValidationConfig.md

@@ -40,3 +40,3 @@ # Hapi Validation Configuration Syntax Documentation

The fairly comprehensive Hapi Validation system can be used to validate querystring parameters and payloads (POST data sent from the client(s)).
The fairly comprehensive Hapi Validation system can be used to validate querystring parameters and payloads (POST data sent from the client(s)). Validation uses the [joi](https://github.com/walmartlabs/joi) module.

@@ -43,0 +43,0 @@ ### Query Example

@@ -40,2 +40,3 @@ /**

{ method: 'GET', path: '/', config: { handler: internals.get, query: { username: S() } } },
{ method: 'POST', path: '/', config: { handler: internals.echo, payload: 'parse' } },
{ method: 'GET', path: '/admin', config: { handler: internals.get, query: { username: S().required().with('password'), password: S() } } },

@@ -77,2 +78,3 @@ { method: 'GET', path: '/users', config: { handler: internals.get, query: { email: S().email().required().min(18) } } },

internals.output = function (request) {

@@ -83,8 +85,15 @@

internals.payload = function (request) {
request.reply('Success!\n');
}
};
internals.echo = function(request) {
request.reply(request.payload);
};
internals.main();

@@ -84,3 +84,3 @@ // Load modules

routes = routes.filter(function(route) {
return route !== null && route.path !== internals.config.docsEndpoint;
return route !== null && route !== undefined && route.path !== internals.config.docsEndpoint;
});

@@ -208,2 +208,2 @@

return element === 'required';
};
};

@@ -6,2 +6,3 @@ // Load modules

var Zlib = require("zlib");
var MultiPart = require('multipart-parser');

@@ -36,2 +37,27 @@

internals.multipartParser = function(contentType) {
var boundary = contentType ? contentType.split(';')[1] : '';
boundary = boundary.substring(boundary.indexOf('=') + 1);
return function(result) {
var parsedParts = [];
MultiPart.create(boundary)
.on('part', function(part) {
parsedParts.push(part);
})
.on('error', function(err) {
parsedParts.push(err);
})
.write(new Buffer(result));
return parsedParts;
};
};
// Read and parse body

@@ -68,2 +94,5 @@

}
else if (mime === 'multipart/form-data') {
parserFunc = internals.multipartParser(contentType);
}
else {

@@ -70,0 +99,0 @@ return next(Err.badRequest('Unsupported content-type: ' + mime));

@@ -62,3 +62,3 @@ // Load modules

this.settings.host = args.host ? args.host.toLowerCase() : 'localhost';
this.settings.port = args.port || (this.settings.tls ? 443 : 80);
this.settings.port = typeof args.port !== 'undefined' ? args.port : (this.settings.tls ? 443 : 80);
this.settings.nickname = this.settings.host + ':' + this.settings.port;

@@ -248,6 +248,19 @@ this.settings.uri = (this.settings.tls ? 'https://' : 'http://') + this.settings.host + ':' + this.settings.port;

internals.Server.prototype.start = function () {
internals.Server.prototype.start = function (callback) {
var self = this;
this.listener.once('listening', function() {
// update the port and uri with what was actually bound
self.settings.port = self.listener.address().port;
self.settings.uri = (self.settings.tls ? 'https://' : 'http://') + self.settings.host + ':' + self.settings.port;
Log.event('info', self.settings.nickname + ': Instance started at ' + self.settings.uri);
if (callback) {
callback();
}
});
this.listener.listen(this.settings.port, this.settings.host);
Log.event('info', this.settings.nickname + ': Instance started at ' + this.settings.uri);
};

@@ -254,0 +267,0 @@

@@ -5,3 +5,3 @@ {

"homepage": "http://hapijs.com",
"version": "0.8.3",
"version": "0.8.4",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",

@@ -34,3 +34,4 @@ "contributors":[

"handlebars": "1.0.x",
"mongodb": "1.1.x"
"mongodb": "1.1.x",
"multipart-parser": "0.x.x"
},

@@ -37,0 +38,0 @@ "devDependencies": {

@@ -11,3 +11,3 @@ ![hapi Logo](https://raw.github.com/walmartlabs/hapi/master/images/hapi.png)

Current version: **0.8.3**
Current version: **0.8.4**

@@ -699,3 +699,3 @@ [![Build Status](https://secure.travis-ci.org/walmartlabs/hapi.png)](http://travis-ci.org/walmartlabs/hapi)

**hapi** supports a rich set of data types and validation rules which are described in detail in [Validation Configuration](./docs/ValidationConfig.md).
**hapi** supports a rich set of data types and validation rules which are described in detail in [Validation Configuration](docs/ValidationConfig.md).
For example:

@@ -702,0 +702,0 @@

@@ -7,7 +7,10 @@ // Load modules

describe('Documentation', function() {
describe('Docs Generator', function() {
var _routeTemplate = '{{#each routes}}{{this.method}}|{{/each}}';
var _indexTemplate = '{{#each routes}}{{this.path}}|{{/each}}';
var _server = null;
var _serverWithoutPost = null;
var _serverUrl = 'http://127.0.0.1:8083';
var _serverWithoutPostUrl = 'http://127.0.0.1:18083';

@@ -19,2 +22,3 @@ var handler = function(request) {

function setupServer(done) {
_server = new Hapi.Server('0.0.0.0', 8083, { authentication: false, docs: { routeTemplate: _routeTemplate, indexTemplate: _indexTemplate }});

@@ -31,3 +35,16 @@ _server.addRoutes([

function setupServerWithoutPost(done) {
_serverWithoutPost = new Hapi.Server('0.0.0.0', 18083, { authentication: false, docs: { routeTemplate: _routeTemplate, indexTemplate: _indexTemplate }});
_serverWithoutPost.addRoutes([
{ method: 'GET', path: '/test', config: { handler: handler, query: { param1: S().required() } } }
]);
_serverWithoutPost.listener.on('listening', function() {
done();
});
_serverWithoutPost.start();
}
function makeRequest(path, callback) {
var next = function(res) {

@@ -46,2 +63,3 @@ return callback(res.result);

it('shows template when correct path is provided', function(done) {
makeRequest('/docs?path=/test', function(res) {

@@ -54,2 +72,3 @@ expect(res).to.equal('GET|POST|');

it('has a Not Found response when wrong path is provided', function(done) {
makeRequest('/docs?path=blah', function(res) {

@@ -62,2 +81,3 @@ expect(res.error).to.equal('Not Found');

it('displays the index if no path is provided', function(done) {
makeRequest('/docs', function(res) {

@@ -70,2 +90,3 @@ expect(res).to.equal('/test|/test|');

it('the index does\'t have the docs endpoint listed', function(done) {
makeRequest('/docs', function(res) {

@@ -76,2 +97,22 @@ expect(res).to.not.contain('/docs');

});
describe('Index', function() {
before(setupServerWithoutPost);
it('doesn\'t throw an error when requesting the index when there are no POST routes', function(done) {
_serverWithoutPost.inject({
method: 'get',
url: _serverWithoutPostUrl + '/docs'
}, function(res) {
expect(res).to.exist;
expect(res.result).to.contain('/test');
done();
});
});
});
});

@@ -17,3 +17,3 @@ // Load modules

server.addRoutes([
{ method: 'GET', path: '/custom', config: { handler: customErrorHandler } },
{ method: 'GET', path: '/custom', config: { handler: customErrorHandler } }
]);

@@ -32,3 +32,3 @@

}, next);
}
};

@@ -35,0 +35,0 @@ function parseHeaders(res) {

@@ -24,2 +24,14 @@ // Load modules

it('defaults to port 80 when a null port is provided', function (done) {
var server = new Server('0.0.0.0', null);
expect(server.settings.port).to.be.equal(80);
done();
});
it('allows a ephemeral port to be set', function (done) {
var server = new Server('0.0.0.0', 0);
expect(server.settings.port).to.be.equal(0);
done();
});
it('defaults to localhost when no host is provided', function (done) {

@@ -173,2 +185,24 @@ var server = new Server();

});
it('calls the callback when one is used', function(done) {
var server = new Server('0.0.0.0', 0);
server.start(function() {
expect(server.settings.host).to.equal('0.0.0.0');
expect(server.settings.port).to.not.equal(0);
done();
});
});
it('calls the callback when not using ephemeral port', function(done) {
var server = new Server('0.0.0.0', 8880);
server.start(function(host, port) {
expect(server.settings.host).to.equal('0.0.0.0');
expect(server.settings.port).to.equal(8880);
done();
});
});
});

@@ -182,8 +216,7 @@

var server = new Server('0.0.0.0', 8089);
server.listener.on('listening', function () {
server.start(function() {
server.stop();
done();
});
server.start();
};

@@ -190,0 +223,0 @@ expect(fn).to.not.throw(Error);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc