koa-lite/test/context.js

26 lines
821 B
JavaScript
Raw Normal View History

2013-08-17 07:15:57 +00:00
'use strict';
var Stream = require('stream');
2013-08-17 07:15:57 +00:00
var koa = require('..');
exports = module.exports = function(req, res){
var socket = new Stream.Duplex();
req = req || { headers: {}, socket: socket, __proto__: Stream.Readable.prototype };
res = res || { _headers: {}, socket: socket, __proto__: Stream.Writable.prototype };
2015-12-02 15:13:01 +00:00
req.socket = req.socket || socket;
res.socket = res.socket || socket;
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 };
res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()] };
return koa().createContext(req, res);
2013-08-17 07:15:57 +00:00
}
exports.request = function(req, res){
return exports(req, res).request;
}
exports.response = function(req, res){
return exports(req, res).response;
}