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

restify

Package Overview
Dependencies
Maintainers
1
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

121

lib/server.js

@@ -229,7 +229,2 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

function _parseContentType(request, response) {
return request.contentType();
}
function _parseApiVersion(request, response) {

@@ -273,3 +268,2 @@ if (request.headers['x-api-version'])

if (!_parseQueryString(request, response)) return false;
if (!_parseContentType(request, response)) return false;

@@ -342,4 +336,5 @@ return true;

if (request._config.contentHandlers[contentType]) {
bParams = request._config
.contentHandlers[contentType](request.body, request, response);
bParams = request._config.contentHandlers[contentType](request.body,
request,
response);
} else if (contentType) {

@@ -461,19 +456,8 @@ return response.sendError(newError({

* 'type'-> function(body, req, res).
* or 'type'-> string where string is a built in
* content type, such as 'application/json'.
* Content types are overideable if you parse in
* a function instead of a string.
* Built in content types are:
* - application/json
* - application/x-www-form-urlencoded
* - application/jsonp
* Defaults to 'application/json'
* - contentWriters: An object of
* 'type' -> function(obj, req, res).
* or 'type' -> string where string is a built in
* content type, such as 'application/json'.
* The function should a return string from the
* passed in Object (obj). The same built in types
* as contentHandlers exist.
* Defaults to application/json.
* - Additionally supports application/jsonp
* - headers: An object of global headers that are sent back

@@ -685,56 +669,61 @@ * on all requests. Restify automatically sets:

// begin contentHandlers/writers
if (!options.contentHandlers)
options.contentHandlers = {'application/json' : 'application/json',
'application/x-www-form-urlencoded' :
'application/x-www-form-urlencoded'};
options.contentHandlers = {};
if (!options.contentWriters)
options.contentWriters = {};
if (typeof(options.contentHandlers) !== 'object')
throw new TypeError('contentHandlers must be an object');
if (typeof(options.contentWriters) !== 'object')
throw new TypeError('contentWriters must be an object');
for (k in options.contentHandlers) {
if (options.contentHandlers.hasOwnProperty(k)) {
if (typeof(options.contentHandlers[k]) === 'function')
server._config.contentHandlers[k] = options.contentHandlers[k];
else if (typeof(options.contentHandlers[k]) === 'string') {
try {
typeH = /^(.*)\/(.*)$/i.exec(options.contentHandlers[k]);
server._config.contentHandlers[k] =
require('./contentTypes/' + typeH[2]).contentHandler();
} catch (errH) {
throw new Error('could not import contentHandler ' +
options.contentHandlers[k]);
}
} else
throw new TypeError('contentWriters values must' +
' be functions or type strings');
}
}
if (!options.contentHandlers['application/json'])
options.contentHandlers['application/json'] = function(body, req, res) {
return JSON.parse(body);
};
if (!options.contentWriters) //set up defaults
options.contentWriters = {'application/json' : 'application/json',
'application/x-www-form-urlencoded' :
'application/x-www-form-urlencoded'};
if (!options.contentHandlers['application/x-www-form-urlencoded'])
options.contentHandlers['application/x-www-form-urlencoded'] =
function(body, req, res) {
return querystring.parse(body) || {};
};
if (typeof(options.contentWriters) !== 'object')
throw new TypeError('contentWriters must be an object');
if (!options.contentWriters['application/json'])
options.contentWriters['application/json'] = function(obj, req, res) {
return JSON.stringify(obj);
};
for (k in options.contentWriters) {
if (options.contentWriters.hasOwnProperty(k)) {
if (typeof(options.contentWriters[k]) === 'function')
server._config.contentWriters[k] = options.contentWriters[k];
else if (typeof(options.contentWriters[k]) === 'string') {
try {
typeW = /^(.*)\/(.*)$/i.exec(options.contentWriters[k]);
server._config.contentWriters[k] =
require('./contentTypes/' + typeW[2]).contentWriter();
} catch (errW) {
throw new Error('could not import contentWriter ' +
options.contentWriters[k]);
}
} else
throw new TypeError('contentWriters values must be' +
' functions or type strings');
}
}
if (!options.contentWriters['application/x-www-form-urlencoded'])
options.contentWriters['application/x-www-form-urlencoded'] =
function(obj, req, res) {
return querystring.stringify(obj) + '\n';
};
if (!options.contentWriters['application/jsonp'])
options.contentWriters['application/jsonp'] = function(obj, req, res) {
var query = url.parse(req.url, true).query;
var cbName = query && query.callback ? query.callback : 'callback';
var response = {
code: res.code,
data: obj
};
res.code = 200;
return cbName + '(' + JSON.stringify(response) + ');';
};
Object.keys(options.contentHandlers).forEach(function(k) {
if (typeof(options.contentHandlers[k]) !== 'function')
throw new TypeError('contentHandlers must be functions');
server._config.contentHandlers[k] = options.contentHandlers[k];
});
Object.keys(options.contentWriters).forEach(function(k) {
if (typeof(options.contentWriters[k]) !== 'function')
throw new TypeError('contentWriters must be functions');
server._config.contentWriters[k] = options.contentWriters[k];
});
// end contentHandlers/writers
if (options.headers) {

@@ -741,0 +730,0 @@ if (typeof(options.headers) !== 'object')

{
"name": "restify",
"description": "REST framework specifically meant for web service APIs",
"version": "0.4.0",
"version": "0.4.1",
"repository": {

@@ -6,0 +6,0 @@ "type": "git",

@@ -34,4 +34,4 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

if (req.params.query) obj.query = req.params.query;
if (req.params.json) obj.json = req.params.json;
if (req.params.form) obj.form = req.params.form;
if (req.params.json) obj.json = req.params.json;
if (req.params.form) obj.form = req.params.form;

@@ -200,5 +200,5 @@ res.send(200, obj);

req.end();
};
};
exports.tearDown = function(test, assert) {

@@ -205,0 +205,0 @@ server.on('close', function() {

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