Skip to content

Instantly share code, notes, and snippets.

@futur
Created June 15, 2012 17:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save futur/2937794 to your computer and use it in GitHub Desktop.
Save futur/2937794 to your computer and use it in GitHub Desktop.
curl node repl (possibly dangerous?)
josh@onix:/tmp/http-repl$ curl -sSNT. localhost:8000
Actual repl over http. NOW WITH A LIMITED CONTEXT!!
>> help
'Exits are North, South and Dennis.'
>> .exit
Terminal exiting.
You'll want to mash ctrl-c.
^C
josh@onix:/tmp/http-repl$
var http = require('http');
var repl = require('repl');
var Stream = require('stream');
var vm = require('vm');
var buf0 = new Buffer([0]);
var server = http.createServer(function (req, res) {
if (!req.headers['user-agent'].match('curl/')) {
res.setHeader('content-type', 'text/plain');
return res.end('curl -sSNT. localhost:8000');
}
res.setHeader('content-type', 'multipart/octet-stream');
res.write('Actual repl over http. NOW WITH A LIMITED CONTEXT!!\r\n');
var stream = new Stream();
stream.readable = true;
stream.writable = true;
stream.write = function (data) {
res.write(data);
};
stream.resume = function () {
req.resume();
};
stream.pause = function () {
res.pause();
};
stream.destroy = function () {
res.write('\r\n');
res.write('Terminal exiting.\r\n');
res.end('You\'ll want to mash ctrl-c.\r\n');
delete stream;
};
req.on('data', function (data) {
stream.emit('data', data);
});
req.on('end', function () {
res.end();
});
var remote = repl.start('>> ', stream);
remote.context = vm.createContext({
help: 'Exits are North, South and Dennis.'
});
var iv = setInterval(function () {
res.write(buf0);
}, 100);
res.on('end', function () {
clearInterval(iv);
});
});
server.listen(8000, 'localhost', function () {
console.log('curl -sSNT. localhost:8000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment