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

restify

Package Overview
Dependencies
Maintainers
0
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.1.22 to 0.1.23

99

lib/server.js

@@ -92,71 +92,64 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

function _parseAccept(request, response) {
response._accept = Constants.ContentTypeJson;
var tmpAccept = Constants.ContentTypeJson;
response._accept = 'application/json';
var accept = null;
if (request.headers.accept && request.headers.accept !== '*/*') {
var _mediaRange = request.headers.accept.split(';');
if (!_mediaRange) {
response.sendError(newError({
httpCode: HttpCodes.BadRequest,
restCode: RestCodes.InvalidArgument,
message: 'Accept header invalid: ' + request.headers.accept
}));
return false;
}
var _acceptTypes = _mediaRange[0].split('/');
if (!_acceptTypes || _acceptTypes.length !== 2) {
response.sendError(newError({
httpCode: HttpCodes.BadRequest,
restCode: RestCodes.InvalidArgument,
message: 'Accept header invalid: ' + request.headers.accept
}));
return false;
}
if (_acceptTypes[0] !== '*') {
var type = request._config._acceptable[_acceptTypes[0]];
if (!type) {
if (log.trace())
log.trace('accept header type doesn\'t match application');
var mediaRanges = request.headers.accept.split(',');
for (var i = 0; i < mediaRanges.length; i++) {
var types = mediaRanges[i].split(';')[0].split('/'); // throw away params
if (!types || types.length !== 2) {
response.sendError(newError({
httpCode: HttpCodes.NotAcceptable,
httpCode: HttpCodes.BadRequest,
restCode: RestCodes.InvalidArgument,
message: request.headers.accept + ' unsupported',
details: request._config.acceptable
message: 'Accept header invalid: ' + request.headers.accept
}));
return false;
}
tmpAccept = _acceptTypes[0] + '/';
}
if (_acceptTypes[1] !== '*') {
var subType;
var subTypes = request._config._acceptable[_acceptTypes[0]];
if (subTypes) {
for (var i = 0; i < subTypes.length; i++) {
if (subTypes[i] === _acceptTypes[1]) {
subType = subTypes[i];
if (types[0] !== '*') {
var subTypes = request._config._acceptable[types[0]];
if (!subTypes)
continue;
accept = types[0] + '/';
if (types[1] !== '*') {
var subType = null;
for (var j = 0; j < subTypes.length; j++) {
if (subTypes[j] === types[1]) {
subType = subTypes[i];
break;
}
}
if (subType) {
accept += subType;
break;
}
} else {
// This is not technically correct, but for all intents and purposes,
// it's good enough for now (but, for example text/* would be screwed
// with this).
accept = 'application/json';
break;
}
} else {
accept = 'application/json';
break;
}
accept = null;
}
if (!subType) {
response.sendError(newError({
httpCode: HttpCodes.NotAcceptable,
restCode: RestCodes.InvalidArgument,
message: request.headers.accept + ' unsupported',
details: request._config.acceptable
}));
return false;
}
tmpAccept += subType;
} else {
tmpAccept = Constants.ContentTypeJson;
if (!accept) {
response.sendError(newError({
httpCode: HttpCodes.NotAcceptable,
restCode: RestCodes.InvalidArgument,
message: request.headers.accept + ' unsupported',
details: request._config.acceptable
}));
return false;
}
response._accept = accept;
}
response._accept = tmpAccept;
if (log.trace())

@@ -163,0 +156,0 @@ log.trace('Parsed accept type as: %s', response._accept);

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

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

@@ -199,1 +199,27 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

};
exports.test_firefox_accept = function(test, assert) {
var server = restify.createServer({
});
var socket = '/tmp/.' + uuid();
server.get('/', _handler);
server.listen(socket, function() {
var opts = common.newOptions(socket, '/');
opts.headers.accept =
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
http.request(opts, function(res) {
common.checkResponse(assert, res);
assert.equal(res.headers.server, 'node.js');
assert.equal(res.statusCode, 200);
server.on('close', function() {
test.finish();
});
server.close();
}).end();
});
};

@@ -10,3 +10,6 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.

assert.ok(response.headers['access-control-allow-origin']);
if (response.statusCode !== 404 && !response._skipAllowedMethods) {
if (response.statusCode !== 400 &&
response.statusCode !== 404 &&
response.statusCode !== 406 &&
!response._skipAllowedMethods) {
assert.ok(response.headers['access-control-allow-methods']);

@@ -13,0 +16,0 @@ }

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