Safe constructors: http.Server and http.Client
authorRyan Dahl <ry@tinyclouds.org>
Fri, 27 Aug 2010 20:58:52 +0000 (13:58 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Fri, 27 Aug 2010 20:58:52 +0000 (13:58 -0700)
lib/http.js
test/simple/test-http.js

index 5fbc592..ea0ce2a 100644 (file)
@@ -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;
 
index 05e6c7e..3d7fc3d 100644 (file)
@@ -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);