Browse files

GH-146 Allow setting of regex flags even if path is a string

  • Loading branch information...
1 parent 93cb90b commit 8a901e8182ecd427a1ca930fba3d0911ead905a2 Mark Cavage committed Jun 2, 2012
Showing with 28 additions and 1 deletion.
  1. +1 −1 lib/route.js
  2. +1 −0 lib/server.js
  3. +26 −0 test/server.test.js
View
2 lib/route.js
@@ -176,7 +176,7 @@ function Route(options) {
self._url = url.parse(u).pathname;
self.pattern = '^';
- self.flags = '';
+ self.flags = options.flags || '';
self.params = [];
self._url.split('/').forEach(function (fragment) {
if (!fragment.length)
View
1 lib/server.js
@@ -418,6 +418,7 @@ Server.prototype._addRoute = function _addRoute(method, options, handlers) {
log: self.log,
method: method,
url: options.path || options.url,
+ flags: options.flags,
handlers: chain,
name: options.name,
version: options.version || self.version,
View
26 test/server.test.js
@@ -527,6 +527,32 @@ test('RegExp ok', function (t) {
});
+test('path+flags ok', function (t) {
+ var server = restify.createServer({ dtrace: DTRACE, log: LOGGER });
+
+ server.get({path: '/foo', flags: 'i'}, function tester(req, res, next) {
+ res.send('hi there');
+ return next();
+ });
+
+ server.listen(PORT, function () {
+ var opts = {
+ hostname: 'localhost',
+ port: PORT,
+ path: '/FOO',
+ method: 'GET',
+ agent: false
+ };
+ http.request(opts, function (res) {
+ t.equal(res.statusCode, 200);
+ server.close(function () {
+ t.end();
+ });
+ }).end();
+ });
+});
+
+
test('GH-56 streaming with filed (download)', function (t) {
var server = restify.createServer({ dtrace: DTRACE, log: LOGGER });

0 comments on commit 8a901e8

Please sign in to comment.