Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lib/restler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ function Request(uri, options) {
console.log("Building multipart request without Content-Length header, please specify all file sizes");
}
} else {
if (typeof this.options.data == 'object') {
this.options.data = qs.stringify(this.options.data);
this.headers['Content-Type'] = 'application/x-www-form-urlencoded';
this.headers['Content-Length'] = this.options.data.length;
}
if(typeof this.options.data == 'string') {
var buffer = new Buffer(this.options.data, this.options.encoding || 'utf8');
this.options.data = buffer;
this.headers['Content-Length'] = buffer.length;
if (!this.data) {
this.data = this.options.data;
if (typeof this.data == 'object') {
this.data = qs.stringify(this.data);
this.headers['Content-Type'] = 'application/x-www-form-urlencoded';
this.headers['Content-Length'] = this.data.length;
}
if(typeof this.data == 'string') {
var buffer = new Buffer(this.data, this.options.encoding || 'utf8');
this.data = buffer;
this.headers['Content-Length'] = buffer.length;
}
}
}

Expand Down Expand Up @@ -125,6 +128,7 @@ mixin(Request.prototype, {
self.url = url.parse(url.resolve(self.url.href, response.headers['location']));
self.options.method = 'GET';
delete self.options.data;
delete self.data;
self._retry();
} else {
self.url = url.parse(url.resolve(self.url.href, response.headers['location']));
Expand Down Expand Up @@ -239,12 +243,12 @@ mixin(Request.prototype, {
run: function() {
var self = this;
if (this.options.multipart) {
multipart.write(this.request, this.options.data, function() {
multipart.write(this.request, this.data, function() {
self.request.end();
});
} else {
if (this.options.data) {
this.request.write(this.options.data.toString(), this.options.encoding || 'utf8');
if (this.data) {
this.request.write(this.data.toString(), this.options.encoding || 'utf8');
}
this.request.end();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "restler",
"version": "2.0.1",
"version": "2.0.2",
"description": "An HTTP client library for node.js",
"contributors": [{ "name": "Dan Webb", "email": "[email protected]" }],
"homepage": "https://github.com/danwrong/restler",
Expand Down