Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add IncomingMessage#toJSON()

  • Loading branch information...
commit 3761aa7a97ffb45761e69c97c34bdbe4e73770f7 1 parent c11c19b
TJ Holowaychuk authored

Showing 2 changed files with 32 additions and 0 deletions. Show diff stats Hide diff stats

  1. +8 0 lib/http.js
  2. +24 0 test/simple/test-http-request-tojson.js
8 lib/http.js
@@ -295,6 +295,14 @@ util.inherits(IncomingMessage, Stream);
295 295
296 296 exports.IncomingMessage = IncomingMessage;
297 297
  298 +IncomingMessage.prototype.toJSON = function(){
  299 + return {
  300 + url: this.url,
  301 + method: this.method,
  302 + headers: this.headers,
  303 + httpVersion: this.httpVersion
  304 + }
  305 +};
298 306
299 307 IncomingMessage.prototype.destroy = function(error) {
300 308 this.socket.destroy(error);
24 test/simple/test-http-request-tojson.js
... ... @@ -0,0 +1,24 @@
  1 +
  2 +var common = require('../common');
  3 +var assert = require('assert');
  4 +var http = require('http');
  5 +
  6 +var server = http.createServer(function(req, res){
  7 + var obj = JSON.parse(JSON.stringify(req));
  8 +
  9 + assert.deepEqual(obj, {
  10 + method: 'GET',
  11 + url: '/something',
  12 + headers: { host: 'localhost:' + common.PORT, connection: 'keep-alive' },
  13 + httpVersion: '1.1'
  14 + });
  15 +
  16 + process.exit(0);
  17 +});
  18 +
  19 +server.listen(common.PORT);
  20 +
  21 +http.get({
  22 + port: common.PORT,
  23 + path: '/something'
  24 +});

0 comments on commit 3761aa7

Please sign in to comment.
Something went wrong with that request. Please try again.