Skip to content

Commit

Permalink
Merge 285853b into e7ffbdf
Browse files Browse the repository at this point in the history
  • Loading branch information
menems committed Oct 21, 2015
2 parents e7ffbdf + 285853b commit c5fc1fc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var basename = path.basename;
var extname = path.extname;
var resolve = path.resolve;
var fs = require('mz/fs');
var co = require('co');

/**
* Expose `send()`.
Expand Down Expand Up @@ -45,8 +46,8 @@ function send(ctx, path, opts) {
var format = opts.format || opts.format === undefined ? true : false;
var gzip = opts.gzip || opts.gzip === undefined ? true : false;

return function *(){
var encoding = this.acceptsEncodings('gzip', 'deflate', 'identity');
return co(function *(){
var encoding = ctx.acceptsEncodings('gzip', 'deflate', 'identity');

// normalize path
path = decode(path);
Expand Down Expand Up @@ -97,7 +98,7 @@ function send(ctx, path, opts) {
ctx.body = fs.createReadStream(path);

return path;
}
});
}

/**
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"index.js"
],
"devDependencies": {
"babel": "^5.8.23",
"istanbul-harmony": "0",
"koa": "1",
"mocha": "^2.3.3",
Expand All @@ -21,13 +22,14 @@
},
"license": "MIT",
"dependencies": {
"co": "^4.6.0",
"debug": "*",
"mz": "^2.0.0",
"resolve-path": "^1.2.1"
},
"scripts": {
"test": "mocha --require should --reporter spec",
"test-cov": "node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require should",
"test-travis": "node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require should"
"test": "mocha --require should --reporter spec test/index.js test/experimental/index.js",
"test-cov": "node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require should test/index.js test/experimental/index.js",
"test-travis": "node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require should test/index.js test/experimental/index.js"
}
}
23 changes: 23 additions & 0 deletions test/experimental/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

var request = require('supertest');
var koa = require('koa');
var send = require('../../');

describe('asyncAwait support with koa experimental', function(){
it('should 200', function(done){
var app = koa();

app.experimental = true;

app.use(async function(){
var ctx = this;
await send(ctx, 'test/fixtures/hello.txt');
});

request(app.listen())
.get('/')
.expect(200)
.expect('world', done);
});
});
7 changes: 7 additions & 0 deletions test/experimental/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

require('babel/register')({
optional: ['asyncToGenerator']
});
require('./async');

0 comments on commit c5fc1fc

Please sign in to comment.