Skip to content
Merged
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
7 changes: 6 additions & 1 deletion lib/multipartform.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ Part.prototype = {
if (this.value.data) {
header = "Content-Disposition: form-data; name=\"" + this.name +
"\"; filename=\"" + this.value.filename + "\"\r\n" +
"Content-Length: " + this.value.data.length + "\r\n" +
"Content-Type: " + this.value.contentType;
} if (this.value instanceof File) {
} else if (this.value instanceof File) {
header = "Content-Disposition: form-data; name=\"" + this.name +
"\"; filename=\"" + this.value.filename + "\"\r\n" +
"Content-Length: " + this.value.fileSize + "\r\n" +
Expand Down Expand Up @@ -127,6 +128,10 @@ Part.prototype = {
});
})(); // reader()
});
} else if (this.value instanceof Data) {
stream.write(this.value.data);
stream.write("\r\n");
callback();
} else {
stream.write(this.value + "\r\n");
callback();
Expand Down
21 changes: 20 additions & 1 deletion test/restler.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,26 @@ module.exports['Multipart'] = {

test.done();
});
}
},

'Test multipart request with Data vars': function(test) {
rest.post(host, {
data: {
a: 10,
b: rest.data('b.txt', 'text/plain', 'thing'),
c: rest.data('c.txt', 'text/plain', new Buffer('thing'))
},
multipart: true
}).on('complete', function(data) {
test.re(data, /content-type\: multipart\/form-data/, 'should set "content-type" header');
test.re(data, /name="a"(\s)+10/, 'should send a=10');
test.re(data, /name="b"; filename="b.txt"\s+Content-Length: 5\s+Content-Type: text\/plain\s+thing\s/, 'should send b=thing');
test.re(data, /name="c"; filename="c.txt"\s+Content-Length: 5\s+Content-Type: text\/plain\s+thing\s/, 'should send c=thing');
test.re(data, /content-length: 410/, 'should send content-length header');

test.done();
});
},

};

Expand Down