2013-08-17 07:15:57 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-05 18:23:47 +00:00
|
|
|
const Stream = require('stream');
|
2015-10-13 06:19:42 +00:00
|
|
|
const Koa = require('../..');
|
2013-08-17 07:15:57 +00:00
|
|
|
|
2015-10-13 06:43:23 +00:00
|
|
|
module.exports = function(req, res){
|
2015-10-05 18:23:47 +00:00
|
|
|
const socket = new Stream.Duplex();
|
2014-08-16 09:58:06 +00:00
|
|
|
req = req || { headers: {}, socket: socket, __proto__: Stream.Readable.prototype };
|
|
|
|
res = res || { _headers: {}, socket: socket, __proto__: Stream.Writable.prototype };
|
2015-10-12 20:36:41 +00:00
|
|
|
res.getHeader = function(k){ return res._headers[k.toLowerCase()]; };
|
|
|
|
res.setHeader = function(k, v){ res._headers[k.toLowerCase()] = v; };
|
|
|
|
res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()]; };
|
2015-10-13 06:19:42 +00:00
|
|
|
return (new Koa()).createContext(req, res);
|
2015-10-12 20:36:41 +00:00
|
|
|
};
|
2013-08-17 07:15:57 +00:00
|
|
|
|
2015-10-13 06:43:23 +00:00
|
|
|
module.exports.request = function(req, res){
|
|
|
|
return module.exports(req, res).request;
|
2015-10-12 20:36:41 +00:00
|
|
|
};
|
2013-11-14 02:34:15 +00:00
|
|
|
|
2015-10-13 06:43:23 +00:00
|
|
|
module.exports.response = function(req, res){
|
|
|
|
return module.exports(req, res).response;
|
2015-10-12 20:36:41 +00:00
|
|
|
};
|