Path: blob/master/6-Selenium/phantomjs/examples/serverkeepalive.js
164 views
var port, server, service,1system = require('system');23if (system.args.length !== 2) {4console.log('Usage: serverkeepalive.js <portnumber>');5phantom.exit(1);6} else {7port = system.args[1];8server = require('webserver').create();910service = server.listen(port, { keepAlive: true }, function (request, response) {11console.log('Request at ' + new Date());12console.log(JSON.stringify(request, null, 4));1314var body = JSON.stringify(request, null, 4);15response.statusCode = 200;16response.headers = {17'Cache': 'no-cache',18'Content-Type': 'text/plain',19'Connection': 'Keep-Alive',20'Keep-Alive': 'timeout=5, max=100',21'Content-Length': body.length22};23response.write(body);24response.close();25});2627if (service) {28console.log('Web server running on port ' + port);29} else {30console.log('Error: Could not create web server listening on port ' + port);31phantom.exit();32}33}343536