Skip to content

Instantly share code, notes, and snippets.

@leozc
Created April 16, 2013 22:23
Show Gist options
  • Save leozc/5400166 to your computer and use it in GitHub Desktop.
Save leozc/5400166 to your computer and use it in GitHub Desktop.
This implementation simulates very very slow HTTP server
/**
This implementation simulates very very slow HTTP server
**/
var http = require('http');
var sleep = require('sleep');
var fs = require('fs');
var timeout = 1000; //sleep 1 seconds
var iteration = 100; //sleep 100 iteration
http.createServer(function (req, res) {
console.log("Request in");
var myi = iteration
setTimeout(sleepMe, timeout);
function sleepMe() {
if(myi!=0){
var response = new Date().toString() + ":"+myi.toString();
console.log(response);
res.write(response);
myi--;
setTimeout(sleepMe,timeout);
}else
{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Hello I am awake");
console.log("Request Done");
}
}
}).listen(8080);
@leozc
Copy link
Author

leozc commented Apr 16, 2013

Use to test HTTP/Socket Timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment