From 44a287987e5eb791dc1092002a35f712d3451b95 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 27 Aug 2010 13:58:52 -0700 Subject: [PATCH] Safe constructors: http.Server and http.Client --- lib/http.js | 2 ++ test/simple/test-http.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/http.js b/lib/http.js index 5fbc5921a4..ea0ce2afc2 100644 --- a/lib/http.js +++ b/lib/http.js @@ -730,6 +730,7 @@ function httpSocketSetup (socket) { function Server (requestListener) { + if (!(this instanceof Server)) return new Server(requestListener); net.Server.call(this); if(requestListener){ @@ -851,6 +852,7 @@ function connectionListener (socket) { function Client ( ) { + if (!(this instanceof Client)) return new Client(); net.Stream.call(this); var self = this; diff --git a/test/simple/test-http.js b/test/simple/test-http.js index 05e6c7e8d2..3d7fc3d065 100644 --- a/test/simple/test-http.js +++ b/test/simple/test-http.js @@ -12,7 +12,7 @@ var responses_recvd = 0; var body0 = ""; var body1 = ""; -var server = http.createServer(function (req, res) { +var server = http.Server(function (req, res) { if (responses_sent == 0) { assert.equal("GET", req.method); assert.equal("/hello", url.parse(req.url).pathname);