Permalink
Browse files

Add copyright notice and comments to the code. Change permissions to …

…executable
  • Loading branch information...
1 parent 434f46e commit 01e1e90fa9ab4d70e5519d19acab1b2b4c157e28 @divyekapoor divyekapoor committed Jan 14, 2011
Showing with 17 additions and 2 deletions.
  1. +17 −2 test_server.js
View
19 test_server.js 100644 → 100755
@@ -1,13 +1,28 @@
+#!/usr/bin/env node
+//
+// Copyright Divye Kapoor 2010
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+//
+// This file is a Node.js based HTTP Server that's useful for testing
+// It echoes back the http request method, the request url, request headers
+// and request body.
+//
+
var http = require('http');
var util = require('util');
var httpServer = http.Server();
httpServer.on('request', function(req, resp) {
- util.log(req.method + ' ' + req.url);
+
+ util.log(req.method + ' ' + req.url); // Keep a timestamped log of requests made to the server
+
resp.writeHead(200, {'content-type':'text/plain'});
- if(req.method !== "HEAD") {
+ if(req.method !== "HEAD") { // No response body allowed for HEAD requests as per HTTP RFC.
resp.write('Method: ' + req.method + '\nUrl: ' + req.url + '\nHeaders:\n' + util.inspect(req.headers, true, null) + '\nData: \n');
req.on('data', function(chunk) {

0 comments on commit 01e1e90

Please sign in to comment.