Skip to content

Instantly share code, notes, and snippets.

@thejhh
Created August 23, 2011 13:41
Show Gist options
  • Save thejhh/1165145 to your computer and use it in GitHub Desktop.
Save thejhh/1165145 to your computer and use it in GitHub Desktop.
A slow HTTP server for testing web clients
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
<p>This is content for development test tool.</p>
</body>
</html>
/* Slow HTTP server for web client testing */
var http = require('http'),
fs = require('fs'),
page = fs.readFileSync('page.html', 'utf-8'),
delay = 250; // delay in ms
http.createServer(function (req, res) {
var i = 0, interval;
res.writeHead(200, {'Content-Type': 'text/html'});
interval = setInterval(function() {
if(i != page.length) {
console.log("Writing next chunk:" + page[i]);
res.write(""+page[i]);
i++;
} else {
console.log("DONE!");
res.end();
clearInterval(interval);
}
}, delay);
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment