Skip to content

Commit

Permalink
Merge pull request #2022 from simov/fix-multipart
Browse files Browse the repository at this point in the history
Convert numeric multipart bodies to string
  • Loading branch information
simov committed Jan 21, 2016
2 parents 90b6347 + 8e98a6e commit 29d8181
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Multipart.prototype.build = function (parts, chunked) {
var body = chunked ? new CombinedStream() : []

function add (part) {
if (typeof part === 'number') {
part = part.toString()
}
return chunked ? body.append(part) : body.push(new Buffer(part))
}

Expand Down
15 changes: 10 additions & 5 deletions tests/test-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@ function runTest(t, a) {
req.on('end', function() {
// check for the fields traces

// 1st field : my_field
// my_field
t.ok(data.indexOf('name: my_field') !== -1)
t.ok(data.indexOf(multipartData[0].body) !== -1)

// my_number
t.ok(data.indexOf('name: my_number') !== -1)
t.ok(data.indexOf(multipartData[1].body) !== -1)

// 2nd field : my_buffer
// my_buffer
t.ok(data.indexOf('name: my_buffer') !== -1)
t.ok(data.indexOf(multipartData[1].body) !== -1)
t.ok(data.indexOf(multipartData[2].body) !== -1)

// 3rd field : my_file
// my_file
t.ok(data.indexOf('name: my_file') !== -1)
// check for unicycle.jpg traces
t.ok(data.indexOf('2005:06:21 01:44:12') !== -1)

// 4th field : remote_file
// remote_file
t.ok(data.indexOf('name: remote_file') !== -1)
// check for http://localhost:6767/file traces
t.ok(data.indexOf('Photoshop ICC') !== -1)
Expand All @@ -73,6 +77,7 @@ function runTest(t, a) {
// @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8
multipartData = [
{name: 'my_field', body: 'my_value'},
{name: 'my_number', body: 1000},
{name: 'my_buffer', body: new Buffer([1, 2, 3])},
{name: 'my_file', body: fs.createReadStream(localFile)},
{name: 'remote_file', body: request('http://localhost:6767/file')}
Expand Down

0 comments on commit 29d8181

Please sign in to comment.