Skip to content

Commit

Permalink
A Node.js based HTTP echo server. Useful for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
divyekapoor committed Jan 14, 2011
1 parent 5dfdc58 commit 434f46e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var http = require('http');
var util = require('util');


var httpServer = http.Server();
httpServer.on('request', function(req, resp) {
util.log(req.method + ' ' + req.url);
resp.writeHead(200, {'content-type':'text/plain'});

if(req.method !== "HEAD") {
resp.write('Method: ' + req.method + '\nUrl: ' + req.url + '\nHeaders:\n' + util.inspect(req.headers, true, null) + '\nData: \n');

req.on('data', function(chunk) {
resp.write(chunk);
});
}

req.on('end', function() {
resp.end();
});

});

httpServer.listen(8090, '127.0.0.1', function() {
console.log('Server started on http://localhost:8090');
});

0 comments on commit 434f46e

Please sign in to comment.