Created
August 23, 2011 13:41
-
-
Save thejhh/1165145 to your computer and use it in GitHub Desktop.
A slow HTTP server for testing web clients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Hello World</title> | |
</head> | |
<body> | |
<h1>Hello World</h1> | |
<p>This is content for development test tool.</p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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