From fcab7f1953cd6fb141a7d98f60580c50b59fb73f Mon Sep 17 00:00:00 2001 From: Derek Bredensteiner Date: Thu, 14 Jun 2012 17:40:41 -0700 Subject: [PATCH 1/4] Adding a line break to the preamble as the first part of a multipart was not recognized by a server I was communicating with. --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index c7b078fb3..fe9664da1 100644 --- a/main.js +++ b/main.js @@ -664,7 +664,7 @@ Request.prototype.multipart = function (multipart) { var body = part.body if(body == null) throw Error('Body attribute missing in multipart.') delete part.body - var preamble = '--' + self.boundary + '\r\n' + var preamble = '\r\n' + '--' + self.boundary + '\r\n' Object.keys(part).forEach(function (key) { preamble += key + ': ' + part[key] + '\r\n' }) From dba2ebf09552258f37b60122c19b236064b0d216 Mon Sep 17 00:00:00 2001 From: Derek Bredensteiner Date: Fri, 6 Jul 2012 10:16:40 -0700 Subject: [PATCH 2/4] Updating with corresponding tests. --- main.js | 3 ++- tests/test-body.js | 2 +- tests/test-https-strict.js | 2 +- tests/test-https.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 690cc9a54..d414a93c7 100644 --- a/main.js +++ b/main.js @@ -663,11 +663,12 @@ Request.prototype.multipart = function (multipart) { if (!multipart.forEach) throw new Error('Argument error, options.multipart.') + self.body.push(new Buffer('\r\n')) multipart.forEach(function (part) { var body = part.body if(body == null) throw Error('Body attribute missing in multipart.') delete part.body - var preamble = '\r\n' + '--' + self.boundary + '\r\n' + var preamble = '--' + self.boundary + '\r\n' Object.keys(part).forEach(function (key) { preamble += key + ': ' + part[key] + '\r\n' }) diff --git a/tests/test-body.js b/tests/test-body.js index bf53917ab..75327ee99 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -52,7 +52,7 @@ var tests = } , testPutMultipart : { resp: server.createPostValidator( - '--__BOUNDARY__\r\n' + + '\r\n--__BOUNDARY__\r\n' + 'content-type: text/html\r\n' + '\r\n' + 'Oh hi.' + diff --git a/tests/test-https-strict.js b/tests/test-https-strict.js index 470b68ddd..161b3262e 100644 --- a/tests/test-https-strict.js +++ b/tests/test-https-strict.js @@ -52,7 +52,7 @@ var tests = } , testPutMultipart : { resp: server.createPostValidator( - '--__BOUNDARY__\r\n' + + '\r\n--__BOUNDARY__\r\n' + 'content-type: text/html\r\n' + '\r\n' + 'Oh hi.' + diff --git a/tests/test-https.js b/tests/test-https.js index 58e7db93f..b9e675a24 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -44,7 +44,7 @@ var tests = } , testPutMultipart : { resp: server.createPostValidator( - '--__BOUNDARY__\r\n' + + '\r\n--__BOUNDARY__\r\n' + 'content-type: text/html\r\n' + '\r\n' + 'Oh hi.' + From 396531d083c94bc807a25f7c3a50a0c92a00c5f7 Mon Sep 17 00:00:00 2001 From: Derek Bredensteiner Date: Fri, 6 Jul 2012 13:47:37 -0700 Subject: [PATCH 3/4] Removing console.log of multipart --- main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.js b/main.js index d414a93c7..f5fab2c38 100644 --- a/main.js +++ b/main.js @@ -659,8 +659,6 @@ Request.prototype.multipart = function (multipart) { self.headers['content-type'] = self.headers['content-type'].split(';')[0] + '; boundary=' + self.boundary; } - console.log('boundary >> ' + self.boundary) - if (!multipart.forEach) throw new Error('Argument error, options.multipart.') self.body.push(new Buffer('\r\n')) From 54226a38816b4169e0a7a5d8b1a7feba78235fec Mon Sep 17 00:00:00 2001 From: Derek Bredensteiner Date: Fri, 6 Jul 2012 14:32:19 -0700 Subject: [PATCH 4/4] Okay, trying it as an optional parameter, with a new test in test-body.js to verify --- main.js | 5 ++++- tests/test-body.js | 17 +++++++++++++++++ tests/test-https-strict.js | 2 +- tests/test-https.js | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index f5fab2c38..a27cf8fa7 100644 --- a/main.js +++ b/main.js @@ -661,7 +661,10 @@ Request.prototype.multipart = function (multipart) { if (!multipart.forEach) throw new Error('Argument error, options.multipart.') - self.body.push(new Buffer('\r\n')) + if (self.preambleCRLF) { + self.body.push(new Buffer('\r\n')) + } + multipart.forEach(function (part) { var body = part.body if(body == null) throw Error('Body attribute missing in multipart.') diff --git a/tests/test-body.js b/tests/test-body.js index 75327ee99..d15e65f1d 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -51,6 +51,22 @@ var tests = , json: {foo: 'bar'} } , testPutMultipart : + { resp: server.createPostValidator( + '--__BOUNDARY__\r\n' + + 'content-type: text/html\r\n' + + '\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__\r\n\r\n' + + 'Oh hi.' + + '\r\n--__BOUNDARY__--' + ) + , method: "PUT" + , multipart: + [ {'content-type': 'text/html', 'body': 'Oh hi.'} + , {'body': 'Oh hi.'} + ] + } + , testPutMultipartPreambleCRLF : { resp: server.createPostValidator( '\r\n--__BOUNDARY__\r\n' + 'content-type: text/html\r\n' + @@ -61,6 +77,7 @@ var tests = '\r\n--__BOUNDARY__--' ) , method: "PUT" + , preambleCRLF: true , multipart: [ {'content-type': 'text/html', 'body': 'Oh hi.'} , {'body': 'Oh hi.'} diff --git a/tests/test-https-strict.js b/tests/test-https-strict.js index 161b3262e..470b68ddd 100644 --- a/tests/test-https-strict.js +++ b/tests/test-https-strict.js @@ -52,7 +52,7 @@ var tests = } , testPutMultipart : { resp: server.createPostValidator( - '\r\n--__BOUNDARY__\r\n' + + '--__BOUNDARY__\r\n' + 'content-type: text/html\r\n' + '\r\n' + 'Oh hi.' + diff --git a/tests/test-https.js b/tests/test-https.js index b9e675a24..58e7db93f 100644 --- a/tests/test-https.js +++ b/tests/test-https.js @@ -44,7 +44,7 @@ var tests = } , testPutMultipart : { resp: server.createPostValidator( - '\r\n--__BOUNDARY__\r\n' + + '--__BOUNDARY__\r\n' + 'content-type: text/html\r\n' + '\r\n' + 'Oh hi.' +