Created
December 9, 2014 19:21
-
-
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
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
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