Skip to content

Commit

Permalink
Deprecate hidden method in favor of setting through options
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jul 12, 2014
1 parent 556b2a0 commit 9b9cf8e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ unreleased
==========

* Deprecate `send.etag()` -- use `etag` in `options`
* Deprecate `send.hidden()` -- use `hidden` in `options`
* deps: debug@1.0.3
- Add support for multiple wildcards in namespaces

Expand Down
4 changes: 0 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ var app = http.createServer(function(req, res){
This can also be a string accepted by the
[ms](https://www.npmjs.org/package/ms#readme) module.

### .hidden(bool)

Enable or disable transfer of hidden files, defaults to false.

## Error-handling

By default when no `error` listeners are present an automatic response will be made, otherwise you have full control over the response, aka you may show a 5xx page etc.
Expand Down
7 changes: 4 additions & 3 deletions lib/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ function SendStream(req, path, options) {
? Boolean(options.etag)
: true

this._hidden = Boolean(options.hidden)

this.maxage(options.maxage);
this.hidden(options.hidden);
this.index(('index' in options) ? options.index : 'index.html');
if (options.root || options.from) this.root(options.root || options.from);
}
Expand Down Expand Up @@ -119,12 +120,12 @@ SendStream.prototype.etag = deprecate.function(function etag(val) {
* @api public
*/

SendStream.prototype.hidden = function(val){
SendStream.prototype.hidden = deprecate.function(function hidden(val) {
val = Boolean(val);
debug('hidden %s', val);
this._hidden = val;
return this;
};
}, 'send.hidden: pass hidden as option');

/**
* Set index `paths`, set to a falsy
Expand Down
41 changes: 33 additions & 8 deletions test/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,20 @@ describe('send(file).pipe(res)', function(){
});
})
})

describe('.hidden()', function(){
it('should default support sending hidden files', function(done){
var app = http.createServer(function(req, res){
send(req, req.url, {root: fixtures})
.hidden(true)
.pipe(res);
});

request(app)
.get('/.hidden')
.expect(200, /secret/, done);
})
})
})

describe('send(file, options)', function(){
Expand All @@ -589,6 +603,25 @@ describe('send(file, options)', function(){
})
})

describe('hidden', function(){
it('should default to false', function(done){
request(app)
.get('/.hidden')
.expect(404, 'Not Found', done)
})

it('should default support sending hidden files', function(done){
var app = http.createServer(function(req, res){
send(req, req.url, {hidden: true, root: fixtures})
.pipe(res);
});

request(app)
.get('/.hidden')
.expect(200, /secret/, done)
})
})

describe('maxAge', function(){
it('should default to 0', function(done){
request(app)
Expand Down Expand Up @@ -707,14 +740,6 @@ describe('send(file, options)', function(){
})
})

describe('hidden', function(){
it('should default to false', function(done){
request(app)
.get('/.secret')
.expect(404, 'Not Found', done)
})
})

describe('root', function(){
it('should set with deprecated from', function(done){
var app = http.createServer(function(req, res){
Expand Down

0 comments on commit 9b9cf8e

Please sign in to comment.