node-rest-client
Advanced tools
Comparing version 1.4.8 to 1.5.0
@@ -193,2 +193,3 @@ var http = require('http'), | ||
options.clientRequest = clientRequest; | ||
options.headers={}; | ||
debug("options pre connect",options); | ||
@@ -200,11 +201,18 @@ debug("args = ", args); | ||
callback = args; | ||
//add Content-length to POST/PUT/DELETE/PATCH methods | ||
if (method === 'POST' || method === 'PUT' || method === 'DELETE' || method === 'PATCH'){ | ||
options.headers['Content-Length'] = 0; | ||
} | ||
} else if (typeof args === 'object') { | ||
// add headers and POST/PUT data to connect options to be passed | ||
// add headers and POST/PUT/DELETE/PATCH data to connect options to be passed | ||
// with request | ||
if (args.headers) options.headers = args.headers; | ||
if (args.headers)options.headers = args.headers; | ||
//always set Content-length header | ||
//set Content lentgh for some servers to work (nginx, apache) | ||
if (args.data !== undefined){ | ||
options.data = args.data; | ||
if (options.headers === undefined)options.headers={}; | ||
// set Content lentgh for some servers to work (nginx) | ||
options.data = args.data; | ||
options.headers['Content-Length'] = Buffer.byteLength((typeof args.data === 'string' ? args.data:JSON.stringify(args.data)), 'utf8'); | ||
}else{ | ||
options.headers['Content-Length'] = 0; | ||
} | ||
@@ -398,3 +406,3 @@ // we have args, go and check if we have parameters | ||
debug("not compressed"); | ||
self.handleResponse(res,Buffer.concat(buffer).toString(),callback); | ||
self.handleResponse(res,Buffer.concat(buffer),callback); | ||
} | ||
@@ -408,7 +416,8 @@ }, | ||
if (this.isXML(content)){ | ||
parseString(data, function (err, result) { | ||
parseString(data.toString(), function (err, result) { | ||
callback(result, res); | ||
}); | ||
}else if (this.isJSON(content)){ | ||
var jsonData; | ||
var jsonData, | ||
data = data.toString(); | ||
try { | ||
@@ -415,0 +424,0 @@ jsonData = this.isValidData(data)?JSON.parse(data):data; |
@@ -5,3 +5,3 @@ { | ||
"description": "node API REST client", | ||
"version": "1.4.8", | ||
"version": "1.5.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type":"git", |
42286
702