Skip to content

Instantly share code, notes, and snippets.

@joshuawscott
Created December 9, 2014 19:21
Show Gist options
  • Save joshuawscott/b63a79ee82fbc0f7e801 to your computer and use it in GitHub Desktop.
Save joshuawscott/b63a79ee82fbc0f7e801 to your computer and use it in GitHub Desktop.
curl to a unix socket. No external dependencies. tested on Nodejs 0.8 & 0.10
var http = require('http');
if (process.argv.length <= 3) {
console.error('USAGE: node curlsocket.js /path/to/unix.sock /request/path');
process.exit();
}
var options = {
method: 'GET',
hostname: 'localhost',
socketPath: process.argv[2],
path: process.argv[3] || '/'
};
console.log(options);
var serverReply = '';
var callback = function (response) {
var serverReply = '';
console.log("\nHEADERS:");
Object.keys(response.headers).forEach(function(k) {
console.log(k + ': ' + response.headers[k]);
});
response.on('data', function(chunk) {
serverReply += chunk;
});
response.on('end', function () {
console.log("\nRESPONSE:");
console.log(serverReply);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment