Skip to content

Commit

Permalink
Defaults multipart chunked to true if not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Nov 11, 2014
1 parent 8c4d81f commit 33cd9e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ Request.prototype.form = function (form) {
Request.prototype.multipart = function (multipart) {
var self = this

var chunked = (multipart instanceof Array) || multipart.chunked
var chunked = (multipart instanceof Array) || (multipart.chunked === undefined) || multipart.chunked
multipart = multipart.data || multipart

var items = chunked ? new CombinedStream() : []
Expand Down
13 changes: 8 additions & 5 deletions tests/test-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function runTest(t, a) {
var remoteFile = path.join(__dirname, 'googledoodle.jpg')
, localFile = path.join(__dirname, 'unicycle.jpg')
, multipartData = []
, chunked = a.array || (a.chunked === undefined) || a.chunked

var server = http.createServer(function(req, res) {
if (req.url === '/file') {
Expand Down Expand Up @@ -37,7 +38,7 @@ function runTest(t, a) {
t.ok( data.indexOf('name: my_buffer') !== -1 )
t.ok( data.indexOf(multipartData[1].body) !== -1 )

if (a.chunked) {
if (chunked) {
// 3rd field : my_file
t.ok( data.indexOf('name: my_file') !== -1 )
// check for unicycle.jpg traces
Expand All @@ -57,7 +58,7 @@ function runTest(t, a) {
server.listen(8080, function() {

// @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8
multipartData = a.chunked
multipartData = chunked
? [
{name: 'my_field', body: 'my_value'},
{name: 'my_buffer', body: new Buffer([1, 2, 3])},
Expand Down Expand Up @@ -90,17 +91,19 @@ function runTest(t, a) {
}

var cases = [
{name: '-json +array', args: {json: false, array: true, chunked: null}},
{name: '-json +array', args: {json: false, array: true}},
{name: '-json -array', args: {json: false, array: false}},
{name: '-json +chunked', args: {json: false, array: false, chunked: true}},
{name: '-json -chunked', args: {json: false, array: false, chunked: false}},

{name: '+json +array', args: {json: true, array: true, chunked: null}},
{name: '+json +array', args: {json: true, array: true}},
{name: '+json -array', args: {json: true, array: false}},
{name: '+json +chunked', args: {json: true, array: false, chunked: true}},
{name: '+json -chunked', args: {json: true, array: false, chunked: false}}
]

cases.forEach(function (test) {
tape('multipart related ' + test.name, function(t) {
runTest.call(null, t, test.args)
runTest(t, test.args)
})
})

0 comments on commit 33cd9e2

Please sign in to comment.