Skip to content

Commit

Permalink
Merge pull request #458 from braydonf/config-payload
Browse files Browse the repository at this point in the history
web: configure payload size
  • Loading branch information
matiu committed Jul 6, 2016
2 parents fa79e69 + b7f888f commit 5351284
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/services/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ var WebService = function(options) {
this.httpsOptions = options.httpsOptions || this.node.httpsOptions;
this.port = options.port || this.node.port || 3456;

// set the maximum size of json payload, defaults to express default
// see: https://github.com/expressjs/body-parser#limit
this.jsonRequestLimit = options.jsonRequestLimit || '100kb';

this.enableSocketRPC = _.isUndefined(options.enableSocketRPC) ?
WebService.DEFAULT_SOCKET_RPC : options.enableSocketRPC;

Expand All @@ -59,7 +63,7 @@ WebService.DEFAULT_SOCKET_RPC = true;
*/
WebService.prototype.start = function(callback) {
this.app = express();
this.app.use(bodyParser.json());
this.app.use(bodyParser.json({limit: this.jsonRequestLimit}));

if(this.https) {
this.transformHttpsOptions();
Expand Down
37 changes: 37 additions & 0 deletions test/services/web.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ describe('WebService', function() {
var web3 = new WebService({node: defaultNode});
web3.enableSocketRPC.should.equal(WebService.DEFAULT_SOCKET_RPC);
});
it('will set configuration options for max payload', function() {
var web = new WebService({node: defaultNode, jsonRequestLimit: '200kb'});
web.jsonRequestLimit.should.equal('200kb');
});
});

describe('#start', function() {
Expand Down Expand Up @@ -75,6 +79,39 @@ describe('WebService', function() {
done();
});
});
it('should pass json request limit to json body parser', function(done) {
var node = new EventEmitter();
var jsonStub = sinon.stub();
var TestWebService = proxyquire('../../lib/services/web', {
http: {
createServer: sinon.stub()
},
https: {
createServer: sinon.stub()
},
fs: fsStub,
express: sinon.stub().returns({
use: sinon.stub()
}),
'body-parser': {
json: jsonStub
},
'socket.io': {
listen: sinon.stub().returns({
on: sinon.stub()
})
}
});
var web = new TestWebService({node: node});
web.start(function(err) {
if (err) {
return done(err);
}
jsonStub.callCount.should.equal(1);
jsonStub.args[0][0].limit.should.equal('100kb');
done();
});
});
});

describe('#stop', function() {
Expand Down

0 comments on commit 5351284

Please sign in to comment.