Comparing version 0.1.6 to 0.1.7
@@ -15,2 +15,7 @@ /* | ||
}; | ||
var CONTENT_TYPE = { | ||
js: 'application/javascript', | ||
css: 'text/css', | ||
json: 'application/json' | ||
}; | ||
@@ -29,2 +34,17 @@ var RE_DELAY_RANGE = /(\d+)-(\d+)/; | ||
function done(req, res, code, headers, body) { | ||
var query = parse(req.url).query, | ||
parsed = qs.parse(query), | ||
type = parsed.type; | ||
if (CONTENT_TYPE[type]) { | ||
headers = mix({ | ||
'Content-Type': CONTENT_TYPE[type] | ||
}, headers); | ||
} | ||
res.writeHead(code, headers); | ||
res.end(body); | ||
} | ||
var rand = exports.rand = function (min, max) { | ||
@@ -49,13 +69,13 @@ return Math.random() * (max - min) + min; | ||
exports.get = function (req, res, body) { | ||
var code = ((req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') ? 200 : 403); | ||
var code = ((req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') ? 200 : 403), | ||
content = body || parse(req.url).query || ''; | ||
res.writeHead(code, headers); | ||
res.end(body || parse(req.url).query || ''); | ||
done(req, res, code, headers, content); | ||
}; | ||
exports['delete'] = function (req, res, body) { | ||
var code = ((req.method === 'DELETE') ? 200 : 403); | ||
var code = ((req.method === 'DELETE') ? 200 : 403), | ||
content = body || parse(req.url).query || ''; | ||
res.writeHead(code, headers); | ||
res.end(body || parse(req.url).query || ''); | ||
done(req, res, code, headers, content); | ||
}; | ||
@@ -85,4 +105,3 @@ | ||
res.writeHead(code, headers); | ||
res.end(body); | ||
done(req, res, code, headers, body); | ||
} | ||
@@ -143,4 +162,4 @@ | ||
} else { | ||
res.writeHead(200, headers); | ||
res.end('waited for ' + seconds + ' seconds'); | ||
done(req, res, 200, headers, 'waited for ' | ||
+ seconds + ' seconds'); | ||
} | ||
@@ -168,6 +187,5 @@ }, seconds * 1000); | ||
res.writeHead(200, mix({ | ||
'Content-Type': 'application/json' | ||
}, headers)); | ||
res.end(json); | ||
done(req, res, 200, mix({ | ||
'Content-Type': CONTENT_TYPE.json | ||
}, headers), json); | ||
}; | ||
@@ -217,6 +235,5 @@ | ||
res.writeHead(code, mix({ | ||
'Content-Type': 'application/json' | ||
}, headers)); | ||
res.end(json); | ||
done(req, res, code, mix({ | ||
'Content-Type': CONTENT_TYPE.json | ||
}, headers), json); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"author": "Dav Glass <davglass@gmail.com>", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"devDependencies": { | ||
@@ -8,0 +8,0 @@ "vows": "*", |
@@ -905,3 +905,35 @@ var vows = require('vows'), | ||
// -- `type` query parameter tests -------------------------------------------- | ||
function assertContentType(route, method) { | ||
var path = '/foo/bar/baz/echo/' + route + '?type=css'; | ||
context = { | ||
topic: function() { | ||
fetch({ | ||
method: method, | ||
path: path | ||
}, this.callback); | ||
} | ||
}; | ||
context[route + ' route should respond with specified content type'] = function (res) { | ||
assert.equal(res.headers['content-type'], 'text/css'); | ||
} | ||
return context; | ||
} | ||
tests['should be loaded'] | ||
['and should load paths'] | ||
['and should respond with specified content type'] = {}; | ||
testRoutes.forEach(function (route) { | ||
tests['should be loaded'] | ||
['and should load paths'] | ||
['and should respond with specified content type'] | ||
['for route ' + route.name] | ||
= assertContentType(route.name, route.method); | ||
}); | ||
vows.describe('echoecho').addBatch(tests).export(module); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49417
1189
43