finished implementation of code to follow documentation. Also made fixes as per pr comments

This commit is contained in:
Almir Kadric
2014-09-19 03:48:50 +00:00
parent d76eb10452
commit 8cfdc83044
7 changed files with 50 additions and 21 deletions

View File

@@ -10,14 +10,12 @@ module.exports = function (url, options, cb) {
try {
if (options.form) {
data = formUrlencoded.encode(options.form);
delete options.form;
options.headers = {
'content-type': 'application/x-www-form-urlencoded',
'content-length': Buffer.byteLength(data)
};
} else if (data.json) {
data = JSON.stringify(data.json);
delete options.json;
options.headers = {
'content-type': 'application/json',
'content-length': Buffer.byteLength(data)

View File

@@ -29,11 +29,7 @@ module.exports = function (requestUrl, options, data, cb) {
});
res.on('end', function () {
if (res.statusCode !== 200) {
return cb(new Error('Received ' + res.statusCode + ' status code with body: ' + responseData));
}
cb(null, responseData);
cb(null, res, responseData);
});
});