Skip to content

Commit

Permalink
Merge pull request #1276 from simov/multipart-get
Browse files Browse the repository at this point in the history
Set transfer encoding for multipart/related to chunked by default
  • Loading branch information
nylen committed Nov 20, 2014
2 parents 7092c68 + f34bef5 commit e543acf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions request.js
Expand Up @@ -1429,6 +1429,10 @@ Request.prototype.multipart = function (multipart) {
return chunked ? items.append(part) : items.push(new Buffer(part))
}

if (chunked) {
self.setHeader('transfer-encoding', 'chunked')
}

var headerName = self.hasHeader('content-type')
if (!headerName || self.headers[headerName].indexOf('multipart') === -1) {
self.setHeader('content-type', 'multipart/related; boundary=' + self.boundary)
Expand Down
12 changes: 8 additions & 4 deletions tests/test-multipart.js
Expand Up @@ -94,7 +94,7 @@ function runTest(t, a) {
if (a.json) {
reqOptions.json = true
}
request.post(reqOptions, function (err, res, body) {
request[a.method](reqOptions, function (err, res, body) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.deepEqual(body, a.json ? {status: 'done'} : 'done')
Expand All @@ -105,6 +105,7 @@ function runTest(t, a) {
})
}

var methods = ['post', 'get']
var cases = [
{name: '-json +array', args: {json: false, array: true}},
{name: '-json -array', args: {json: false, array: false}},
Expand All @@ -127,8 +128,11 @@ var cases = [
{name: '+json +headers -chunked', args: {json: true, headers: true, array: false, chunked: false}}
]

cases.forEach(function (test) {
tape('multipart related ' + test.name, function(t) {
runTest(t, test.args)
methods.forEach(function(method) {
cases.forEach(function (test) {
tape('multipart related ' + method + ' ' + test.name, function(t) {
test.args.method = method
runTest(t, test.args)
})
})
})

0 comments on commit e543acf

Please sign in to comment.