Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup validation and make it optional. Closes #75
- Loading branch information
1 parent
56eb804
commit df67229
Showing
4 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,52 @@ | |
|
||
// Load modules | ||
|
||
const Hoek = require('hoek'); | ||
const Joi = require('joi'); | ||
const Request = require('./request'); | ||
const Response = require('./response'); | ||
const Schema = require('./schema'); | ||
|
||
|
||
// Declare internals | ||
|
||
const internals = {}; | ||
|
||
|
||
internals.options = Joi.object().keys({ | ||
url: Joi.alternatives([ | ||
Joi.string(), | ||
Joi.object().keys({ | ||
protocol: Joi.string(), | ||
hostname: Joi.string(), | ||
port: Joi.any(), | ||
pathname: Joi.string().required(), | ||
query: Joi.any() | ||
}) | ||
]) | ||
.required(), | ||
headers: Joi.object(), | ||
payload: Joi.any(), | ||
simulate: { | ||
end: Joi.boolean(), | ||
split: Joi.boolean(), | ||
error: Joi.boolean(), | ||
close: Joi.boolean() | ||
}, | ||
authority: Joi.string(), | ||
remoteAddress: Joi.string(), | ||
method: Joi.string(), | ||
validate: Joi.boolean() | ||
}); | ||
|
||
|
||
exports.inject = function (dispatchFunc, options, callback) { | ||
|
||
Joi.assert({ dispatchFunc, options, callback }, Schema); | ||
options = (typeof options === 'string' ? { url: options } : options); | ||
|
||
if (options.validate !== false) { // Defaults to true | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Marsup
Contributor
|
||
Hoek.assert(typeof dispatchFunc === 'function', 'Invalid dispatch function'); | ||
Joi.assert(options, internals.options); | ||
} | ||
|
||
const req = new Request(options); | ||
const res = new Response(req, callback); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Turning validation off is a performance optimization. If you are passing garbage, it's your bug, not the modules' problem.