2013-08-17 07:15:57 +00:00
|
|
|
|
2014-04-09 16:02:13 +00:00
|
|
|
var ReadableStream = require('stream').Readable;
|
2013-11-14 02:34:15 +00:00
|
|
|
var context = require('../lib/context');
|
|
|
|
var request = require('../lib/request');
|
|
|
|
var response = require('../lib/response');
|
2013-08-17 07:15:57 +00:00
|
|
|
var koa = require('..');
|
|
|
|
|
2013-11-14 02:34:15 +00:00
|
|
|
exports = module.exports = function(req, res){
|
2014-04-09 16:02:13 +00:00
|
|
|
req = req || { headers: {}, socket: new ReadableStream() };
|
2013-08-17 07:15:57 +00:00
|
|
|
res = res || { _headers: {} };
|
2014-06-05 23:04:31 +00:00
|
|
|
res.getHeader = function(k){ return res._headers[k.toLowerCase()] };
|
2013-08-17 07:15:57 +00:00
|
|
|
res.setHeader = function(k, v){ res._headers[k.toLowerCase()] = v };
|
2013-11-24 13:06:35 +00:00
|
|
|
res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()] };
|
2013-11-14 02:34:15 +00:00
|
|
|
return koa().createContext(req, res);
|
2013-08-17 07:15:57 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 02:34:15 +00:00
|
|
|
exports.context = function(req, res){
|
|
|
|
return exports(req, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.request = function(req, res){
|
|
|
|
return exports(req, res).request;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.response = function(req, res){
|
|
|
|
return exports(req, res).response;
|
2014-04-09 16:02:13 +00:00
|
|
|
}
|