Comparing version 1.0.1 to 1.0.2
@@ -433,2 +433,4 @@ // Load modules | ||
var self = this; | ||
var path = Hoek.uniqueFilename(this.settings.uploads || Os.tmpDir()); | ||
@@ -440,2 +442,3 @@ var file = Fs.createWriteStream(path, { flags: 'wx' }); | ||
self.req.removeListener('aborted', onAbort); | ||
file.removeListener('close', finalize); | ||
@@ -458,2 +461,9 @@ file.removeListener('error', finalize); | ||
var onAbort = function () { | ||
return finalize(Boom.badRequest('Client connection aborted')); | ||
}; | ||
this.req.once('aborted', onAbort); | ||
stream.pipe(counter).pipe(file); | ||
@@ -460,0 +470,0 @@ }; |
{ | ||
"name": "subtext", | ||
"description": "HTTP payload parsing", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"repository": "git://github.com/hapijs/payload", | ||
@@ -26,4 +26,5 @@ "main": "index", | ||
"devDependencies": { | ||
"code": "1.x.x", | ||
"form-data": "0.1.x", | ||
"lab": "4.x.x" | ||
"lab": "5.x.x" | ||
}, | ||
@@ -30,0 +31,0 @@ "scripts": { |
@@ -8,2 +8,3 @@ // Load modules | ||
var Zlib = require('zlib'); | ||
var Code = require('code'); | ||
var FormData = require('form-data'); | ||
@@ -26,3 +27,3 @@ var Hoek = require('hoek'); | ||
var it = lab.it; | ||
var expect = Lab.expect; | ||
var expect = Code.expect; | ||
@@ -40,3 +41,3 @@ | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/json'); | ||
@@ -57,3 +58,3 @@ expect(Buffer.isBuffer(parsed.payload)).to.be.true; | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/json'); | ||
@@ -73,3 +74,3 @@ expect(parsed.payload).to.deep.equal(JSON.parse(payload)); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/json'); | ||
@@ -92,3 +93,3 @@ Wreck.read(parsed.payload, null, function (err, result) { | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/json'); | ||
@@ -113,3 +114,3 @@ Wreck.read(parsed.payload, null, function (err, result) { | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/json-patch+json'); | ||
@@ -129,3 +130,3 @@ expect(parsed.payload).to.deep.equal(JSON.parse(payload)); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/json'); | ||
@@ -147,3 +148,3 @@ expect(parsed.payload).to.deep.equal({}); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid content-type header'); | ||
@@ -164,3 +165,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Unsupported Media Type'); | ||
@@ -181,3 +182,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Payload content length greater than maximum allowed: 10'); | ||
@@ -197,3 +198,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Payload content length greater than maximum allowed: 10'); | ||
@@ -212,3 +213,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid request payload JSON format'); | ||
@@ -236,3 +237,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload).to.deep.equal(JSON.parse(payload)); | ||
@@ -261,3 +262,3 @@ expect(raw).to.equal(payload); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.toString()).to.deep.equal(payload); | ||
@@ -276,3 +277,3 @@ expect(raw).to.equal(payload); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
@@ -301,3 +302,3 @@ var receivedContents = Fs.readFileSync(parsed.payload.path); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
@@ -327,3 +328,3 @@ var receivedContents = Fs.readFileSync(parsed.payload.path); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
@@ -345,3 +346,3 @@ var receivedContents = Fs.readFileSync(parsed.payload.path); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.contain('ENOENT'); | ||
@@ -359,3 +360,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.contain('ENOENT'); | ||
@@ -376,3 +377,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/octet-stream'); | ||
@@ -395,3 +396,3 @@ expect(Buffer.isBuffer(parsed.payload)).to.be.true; | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/json'); | ||
@@ -413,3 +414,3 @@ expect(parsed.payload).to.deep.equal(JSON.parse(payload)); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('text/plain'); | ||
@@ -431,3 +432,3 @@ expect(parsed.payload).to.deep.equal(payload); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('text/plain'); | ||
@@ -449,3 +450,3 @@ expect(parsed.payload).to.deep.equal(payload); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('text/plain'); | ||
@@ -467,3 +468,3 @@ expect(parsed.payload).to.deep.equal(payload); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Unsupported Media Type'); | ||
@@ -484,3 +485,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Unsupported Media Type'); | ||
@@ -501,3 +502,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/x-www-form-urlencoded'); | ||
@@ -519,3 +520,3 @@ expect(parsed.payload.x).to.equal('abc'); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.mime).to.equal('application/x-www-form-urlencoded'); | ||
@@ -537,3 +538,3 @@ expect(parsed.payload).to.deep.equal({ x: { y: '1', z: '2' } }); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid compressed payload'); | ||
@@ -554,3 +555,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid compressed payload'); | ||
@@ -573,3 +574,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload).to.deep.equal(JSON.parse(payload)); | ||
@@ -593,3 +594,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.toString()).to.equal(payload); | ||
@@ -613,3 +614,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload).to.deep.equal(JSON.parse(payload)); | ||
@@ -633,3 +634,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.toString()).to.equal(payload); | ||
@@ -678,3 +679,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload).to.deep.equal({ | ||
@@ -707,3 +708,3 @@ x: ['First', 'Second', 'Third'], | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.pics).to.deep.equal({}); | ||
@@ -751,3 +752,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid content-type header: multipart missing boundary'); | ||
@@ -773,3 +774,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.equal('Invalid multipart payload format'); | ||
@@ -796,3 +797,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.pics.toString()).to.equal('... contents of file1.txt ...\r'); | ||
@@ -819,3 +820,3 @@ done(); | ||
expect(err).to.exist; | ||
expect(err).to.exist(); | ||
expect(err.message).to.contain('/no/such/folder/a/b/c'); | ||
@@ -853,3 +854,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.files[0].hapi).to.deep.equal({ filename: 'file1.txt', headers: { 'content-disposition': 'form-data; name="files"; filename="file1.txt"', 'content-type': 'text/plain' } }); | ||
@@ -886,3 +887,3 @@ expect(parsed.payload.files[1].hapi).to.deep.equal({ filename: 'file2.txt', headers: { 'content-disposition': 'form-data; name="files"; filename="file2.txt"', 'content-type': 'text/plain' } }); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
@@ -892,4 +893,4 @@ expect(parsed.payload.my_file.bytes).to.equal(stats.size); | ||
var sourceContents = Fs.readFileSync(path); | ||
var receivedContents = Fs.readFileSync(parsed.payload['my_file'].path); | ||
Fs.unlinkSync(parsed.payload['my_file'].path); | ||
var receivedContents = Fs.readFileSync(parsed.payload.my_file.path); | ||
Fs.unlinkSync(parsed.payload.my_file.path); | ||
expect(sourceContents).to.deep.equal(receivedContents); | ||
@@ -912,5 +913,7 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.file1.bytes).to.equal(stats.size); | ||
expect(parsed.payload.file2.bytes).to.equal(stats.size); | ||
Fs.unlinkSync(parsed.payload.file1.path); | ||
Fs.unlinkSync(parsed.payload.file2.path); | ||
done(); | ||
@@ -942,4 +945,4 @@ }); | ||
var form = new FormData(); | ||
form.append('file1', Fs.createReadStream(path)); | ||
form.append('file2', Fs.createReadStream(path)); | ||
form.append('a', Fs.createReadStream(path)); | ||
form.append('b', Fs.createReadStream(path)); | ||
form.headers = form.getHeaders(); | ||
@@ -949,5 +952,8 @@ | ||
expect(err).to.not.exist; | ||
expect(parsed.payload.file1.bytes).to.equal(stats.size); | ||
expect(parsed.payload.file2.bytes).to.equal(stats.size); | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.a.bytes).to.equal(stats.size); | ||
expect(parsed.payload.b.bytes).to.equal(stats.size); | ||
// The first file is never written due to createWriteStream() above | ||
Fs.unlinkSync(parsed.payload.b.path); | ||
done(); | ||
@@ -967,3 +973,3 @@ }); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
var fileContents = Fs.readFileSync(path); | ||
@@ -1021,3 +1027,3 @@ expect(parsed.payload.my_file.name).to.equal('subtext'); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.x).to.deep.equal(['First', 'Second', 'Third']); | ||
@@ -1044,5 +1050,5 @@ expect(parsed.payload.field1).to.deep.equal(['Joe Blow\r\nalmost tricked you!', 'Repeated name segment']); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload['my_file'].hapi).to.deep.equal({ | ||
expect(parsed.payload.my_file.hapi).to.deep.equal({ | ||
filename: 'image.jpg', | ||
@@ -1055,5 +1061,5 @@ headers: { | ||
Wreck.read(parsed.payload['my_file'], null, function (err, buffer) { | ||
Wreck.read(parsed.payload.my_file, null, function (err, buffer) { | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(fileContents.length).to.equal(buffer.length); | ||
@@ -1085,3 +1091,3 @@ expect(fileContents.toString('binary') === buffer.toString('binary')).to.equal(true); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.a.b + parsed.payload.a.c).to.equal('34'); | ||
@@ -1116,3 +1122,3 @@ done(); | ||
expect(err).to.not.exist; | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.a.b + parsed.payload.file + parsed.payload.a.c).to.equal('3and4'); | ||
@@ -1122,2 +1128,41 @@ done(); | ||
}); | ||
it('cleans file when stream is aborted', function (done) { | ||
var path = Path.join(__dirname, 'file'); | ||
var count = Fs.readdirSync(path).length; | ||
var server = Http.createServer(); | ||
server.on('request', function (req, res) { | ||
Subtext.parse(req, null, { parse: false, output: 'file', uploads: path }, function (err, parsed) { | ||
expect(Fs.readdirSync(path).length).to.equal(count); | ||
done(); | ||
}); | ||
}); | ||
server.listen(0, function () { | ||
var options = { | ||
hostname: 'localhost', | ||
port: server.address().port, | ||
path: '/', | ||
method: 'POST', | ||
headers: { 'content-length': 1000000 } | ||
}; | ||
var req = Http.request(options, function (res) { }); | ||
req.on('error', function (err) { }); | ||
var random = new Buffer(100000); | ||
req.write(random); | ||
req.write(random); | ||
setTimeout(function () { | ||
req.abort(); | ||
}, 10); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
234393
1178
3