diff --git a/lib/restler.js b/lib/restler.js index 2664233..83a68a4 100644 --- a/lib/restler.js +++ b/lib/restler.js @@ -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; + } } } @@ -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'])); @@ -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(); } diff --git a/package.json b/package.json index c96f316..3fe5d78 100644 --- a/package.json +++ b/package.json @@ -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": "dan@danwebb.net" }], "homepage": "https://github.com/danwrong/restler",