Skip to content
This repository was archived by the owner on Jul 12, 2019. It is now read-only.

Commit 1a736d2

Browse files
Jeff StamerjohnJeff Stamerjohn
authored andcommitted
Merge pull request #1 from HBOCodeLabs/jstamerj/retryFix
Fix retried requests (ATV-660)
2 parents 2c016ef + f84314d commit 1a736d2

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lib/restler.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,18 @@ function Request(uri, options) {
6363
console.log("Building multipart request without Content-Length header, please specify all file sizes");
6464
}
6565
} else {
66-
if (typeof this.options.data == 'object') {
67-
this.options.data = qs.stringify(this.options.data);
68-
this.headers['Content-Type'] = 'application/x-www-form-urlencoded';
69-
this.headers['Content-Length'] = this.options.data.length;
70-
}
71-
if(typeof this.options.data == 'string') {
72-
var buffer = new Buffer(this.options.data, this.options.encoding || 'utf8');
73-
this.options.data = buffer;
74-
this.headers['Content-Length'] = buffer.length;
66+
if (!this.data) {
67+
this.data = this.options.data;
68+
if (typeof this.data == 'object') {
69+
this.data = qs.stringify(this.data);
70+
this.headers['Content-Type'] = 'application/x-www-form-urlencoded';
71+
this.headers['Content-Length'] = this.data.length;
72+
}
73+
if(typeof this.data == 'string') {
74+
var buffer = new Buffer(this.data, this.options.encoding || 'utf8');
75+
this.data = buffer;
76+
this.headers['Content-Length'] = buffer.length;
77+
}
7578
}
7679
}
7780

@@ -125,6 +128,7 @@ mixin(Request.prototype, {
125128
self.url = url.parse(url.resolve(self.url.href, response.headers['location']));
126129
self.options.method = 'GET';
127130
delete self.options.data;
131+
delete self.data;
128132
self._retry();
129133
} else {
130134
self.url = url.parse(url.resolve(self.url.href, response.headers['location']));
@@ -239,12 +243,12 @@ mixin(Request.prototype, {
239243
run: function() {
240244
var self = this;
241245
if (this.options.multipart) {
242-
multipart.write(this.request, this.options.data, function() {
246+
multipart.write(this.request, this.data, function() {
243247
self.request.end();
244248
});
245249
} else {
246-
if (this.options.data) {
247-
this.request.write(this.options.data.toString(), this.options.encoding || 'utf8');
250+
if (this.data) {
251+
this.request.write(this.data.toString(), this.options.encoding || 'utf8');
248252
}
249253
this.request.end();
250254
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "restler",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "An HTTP client library for node.js",
55
"contributors": [{ "name": "Dan Webb", "email": "[email protected]" }],
66
"homepage": "https://github.com/danwrong/restler",

0 commit comments

Comments
 (0)