Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add passing of req explicitly for now (YUCK)

  • Loading branch information...
commit 403e0136697c62bf4188fef29059a1f6aded5090 1 parent 02d2826
@tj tj authored
Showing with 13 additions and 11 deletions.
  1. +7 −5 lib/send.js
  2. +6 −6 test/send.js
View
12 lib/send.js
@@ -29,15 +29,16 @@ exports = module.exports = send;
exports.mime = mime;
/**
- * Return a `SendStream` for `path`.
+ * Return a `SendStream` for `req` and `path`.
*
+ * @param {Request} req
* @param {String} path
* @return {SendStream}
* @api public
*/
-function send(path) {
- return new SendStream(path);
+function send(req, path) {
+ return new SendStream(req, path);
}
/**
@@ -50,12 +51,14 @@ function send(path) {
* - `end` streaming has completed
* - `directory` a directory was requested
*
+ * @param {Request} req
* @param {String} path
* @api private
*/
-function SendStream(path) {
+function SendStream(req, path) {
var self = this;
+ this.req = req;
this.path = path;
this.maxage(0);
this.hidden(false);
@@ -286,7 +289,6 @@ SendStream.prototype.pipe = function(res){
// references
this.res = res;
- this.req = res.socket.parser.incoming; // TODO: wtf?
// invalid request uri
path = utils.decode(path);
View
12 test/send.js
@@ -19,7 +19,7 @@ var app = http.createServer(function(req, res){
res.end('Redirecting to ' + req.url + '/');
}
- send('test/fixtures' + req.url)
+ send(req, 'test/fixtures' + req.url)
.on('error', error)
.on('directory', redirect)
.pipe(res);
@@ -138,7 +138,7 @@ describe('send(file).pipe(res)', function(){
describe('when no "directory" listeners are present', function(){
it('should respond with a redirect', function(done){
var app = http.createServer(function(req, res){
- send(req.url)
+ send(req, req.url)
.root('test/fixtures')
.pipe(res);
});
@@ -155,7 +155,7 @@ describe('send(file).pipe(res)', function(){
describe('when no "error" listeners are present', function(){
it('should respond to errors directly', function(done){
var app = http.createServer(function(req, res){
- send('test/fixtures' + req.url).pipe(res);
+ send(req, 'test/fixtures' + req.url).pipe(res);
});
request(app)
@@ -303,7 +303,7 @@ describe('send(file, options)', function(){
it('should support Infinity', function(done){
var app = http.createServer(function(req, res){
- send('test/fixtures/name.txt')
+ send(req, 'test/fixtures/name.txt')
.maxage(Infinity)
.pipe(res);
});
@@ -338,7 +338,7 @@ describe('send(file, options)', function(){
describe('when given', function(){
it('should join root', function(done){
var app = http.createServer(function(req, res){
- send(req.url)
+ send(req, req.url)
.root(__dirname + '/fixtures')
.pipe(res);
});
@@ -351,7 +351,7 @@ describe('send(file, options)', function(){
it('should restrict paths to within root', function(done){
var app = http.createServer(function(req, res){
- send(req.url)
+ send(req, req.url)
.root(__dirname + '/fixtures')
.on('error', function(err){ res.end(err.message) })
.pipe(res);

0 comments on commit 403e013

Please sign in to comment.
Something went wrong with that request. Please try again.