http-sync is a compiled Node.js extension that provides syncronous http calls.
You must have libcurl installed in order to compile this extension.
On Ubuntu, you can run: sudo apt-get install libcurl4-openssl-dev
On CentOS, you can run: sudo yum install libcurl libcurl-devel
// example with default optionshttpSync=require('http-sync');varrequest=httpSync.request({method: 'GET',headers: {},body: '',protocol: 'http',host: '127.0.0.1',port: 80,//443 if protocol = httpspath: '/'});vartimedout=false;req.setTimeout(10,function(){console.log("Request Timedout!");timedout=true;});varresponse=request.end();if(!timedout){console.log(response);console.log(response.body.toString());}If you require the use of a private CA or client certificate authentication, the following options are available:
- pfx - Path to certificate, private key and CA certificates to use
- ca - Path to an authority certificate
- cert - Path to the public x509 client certificate to use
- key - Path to the private key used for SSL
- passphrase - A string of passphrase for the private key or pfx, if required
// example with a private CA and client cert authenticationhttpSync=require('http-sync');varrequest=httpSync.request({method: 'GET',headers: {},body: '',protocol: 'https',host: '127.0.0.1',port: 443,// protocol = httpspath: '/',ca: '/path/to/CA',cert: '/path/to/crt',key: '/path/to/key',rejectUnauthorized: true});vartimedout=false;req.setTimeout(10,function(){console.log("Request Timedout!");timedout=true;});varresponse=request.end();if(!timedout){console.log(response);console.log(response.body.toString());}node-gyp configure && node-gyp build
You will need:
- node.js source code
- v8 source code
- libcurl development package
Building:
node-waf configure && node-waf build
Run the test.js file:
node test.js