Permalink
Browse files

add ServerResponse#toJSON()

  • Loading branch information...
1 parent 3761aa7 commit b8492f6edfb2332f16b886088d56ea73c21f55dc @tj committed Oct 18, 2012
Showing with 36 additions and 0 deletions.
  1. +7 −0 lib/http.js
  2. +29 −0 test/simple/test-http-response-tojson.js
View
@@ -922,6 +922,13 @@ exports.ServerResponse = ServerResponse;
ServerResponse.prototype.statusCode = 200;
+ServerResponse.prototype.toJSON = function(){
+ return {
+ statusCode: this.statusCode,
+ headers: this._headers
+ }
+};
+
function onServerResponseClose() {
this._httpMessage.emit('close');
}
@@ -0,0 +1,29 @@
+
+var common = require('../common');
+var assert = require('assert');
+var http = require('http');
+
+var server = http.createServer(function(req, res){
+ res.statusCode = 400;
+ res.setHeader('Content-Length', '5');
+ res.setHeader('Content-Type', 'text/plain');
+
+ var obj = JSON.parse(JSON.stringify(res));
+
+ assert.deepEqual(obj, {
+ statusCode: 400,
+ headers: {
+ 'content-length': '5',
+ 'content-type': 'text/plain'
+ }
+ });
+
+ process.exit(0);
+});
+
+server.listen(common.PORT);
+
+http.get({
+ port: common.PORT,
+ path: '/something'
+});

0 comments on commit b8492f6

Please sign in to comment.