Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
const req = http.request(options, res => {
res.setEncoding('utf8')
this[onResponse](res, resolve, reject)
})
req.on('error', err => {
console.error(`problem with request: ${err.message}`)
})
// write data to request body
if (form) {
req.write(form)
}
req.end()
})
}
return new Promise(function(resolve, reject) {
var http = require('http');
var url = require('url');
var options = url.parse(config.http.url);
options.method = 'POST';
var req = http.request(options, function(res) {
console.log('Received HTTP response status code: ' + res.statusCode);
resolve(config);
});
req.on('error', function(err) {
reject('An error occurred when making an HTTP request: ' + err);
});
var keyData = config.http.keyData || 'data';
req.write(config[keyData]);
req.end();
});
};
return new Promise(function (resolve, reject) {
var req = http.request(options, function (res) {
res.setEncoding('utf8');
_this[onResponse](res, resolve, reject);
});
req.on('error', function (err) {
console.error('problem with request: ' + err.message);
});
if (form) {
req.write(form);
}
req.end();
});
}
_.each(pingList, function (pingHost) {
let options = {
hostname: pingHost.host,
path: pingHost.path,
method: 'POST'
};
let req;
req = http.request(options);
req.write(pingXML);
req.on('error', function (error) {
console.error(error.stack);
});
req.end();
});
}
return new Promise((resolve, reject) => {
let buffer = '';
const req = http.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', chunk => buffer += chunk);
res.on('end', () => resolve(buffer));
});
req.on('error', (err) => reject(err));
req.write(payload);
req.end();
});
}