Comparing version 2.0.0 to 2.0.1
// Load modules | ||
var Crypto = require('crypto'); | ||
var Fs = require('fs'); | ||
var Os = require('os'); | ||
var Path = require('path'); | ||
var Stream = require('stream'); | ||
@@ -8,0 +6,0 @@ var Zlib = require('zlib'); |
{ | ||
"name": "subtext", | ||
"description": "HTTP payload parsing", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"repository": "git://github.com/hapijs/subtext", | ||
@@ -28,3 +28,3 @@ "main": "lib/index.js", | ||
"form-data": "0.1.x", | ||
"lab": "5.x.x" | ||
"lab": "6.x.x" | ||
}, | ||
@@ -31,0 +31,0 @@ "scripts": { |
#subtext | ||
HTTP payload parsing. | ||
HTTP payload parser. | ||
[![Build Status](https://secure.travis-ci.org/hapijs/subtext.png)](http://travis-ci.org/hapijs/subtext) | ||
Lead Maintainer - [Eran Hammer](https://github.com/hueniverse) | ||
Lead Maintainer - [John Brett](https://github.com/johnbrett) | ||
subtext parses the request body and exposes it in a callback. | ||
## Example | ||
```javascript | ||
var Http = require('http'); | ||
var Subtext = require('subtext'); | ||
Http.createServer(function (request, response) { | ||
Subtext.parse(request, null, { parse: true, output: 'data' }, function (err, parsed) { | ||
response.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
response.end('Payload contains: ' + parsed.payload.toString()); | ||
}); | ||
}).listen(1337, '127.0.0.1'); | ||
console.log('Server running at http://127.0.0.1:1337/'); | ||
``` | ||
## API | ||
See the [API Reference](API.md) |
@@ -11,3 +11,2 @@ // Load modules | ||
var FormData = require('form-data'); | ||
var Hoek = require('hoek'); | ||
var Lab = require('lab'); | ||
@@ -1122,2 +1121,91 @@ var Subtext = require('..'); | ||
it('parses multiple files of different sizes', function (done) { | ||
var path = Path.join(__dirname, './file/smallimage.png'); | ||
var path2 = Path.join(__dirname, './file/image.jpg'); | ||
var stats = Fs.statSync(path); | ||
var stats2 = Fs.statSync(path2); | ||
var form = new FormData(); | ||
form.append('file1', Fs.createReadStream(path)); | ||
form.append('file2', Fs.createReadStream(path2)); | ||
form.headers = form.getHeaders(); | ||
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) { | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.file1.bytes).to.equal(stats.size); | ||
expect(parsed.payload.file2.bytes).to.equal(stats2.size); | ||
Fs.unlinkSync(parsed.payload.file1.path); | ||
Fs.unlinkSync(parsed.payload.file2.path); | ||
done(); | ||
}); | ||
}); | ||
it('parses multiple files of different sizes', function (done) { | ||
var path = Path.join(__dirname, './file/image.jpg'); | ||
var path2 = Path.join(__dirname, './file/smallimage.png'); | ||
var stats = Fs.statSync(path); | ||
var stats2 = Fs.statSync(path2); | ||
var form = new FormData(); | ||
form.append('file1', Fs.createReadStream(path)); | ||
form.append('file2', Fs.createReadStream(path2)); | ||
form.headers = form.getHeaders(); | ||
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) { | ||
expect(err).to.not.exist(); | ||
expect(parsed.payload.file1.bytes).to.equal(stats.size); | ||
expect(parsed.payload.file2.bytes).to.equal(stats2.size); | ||
Fs.unlinkSync(parsed.payload.file1.path); | ||
Fs.unlinkSync(parsed.payload.file2.path); | ||
done(); | ||
}); | ||
}); | ||
it('parses multiple small files', function (done) { | ||
var path = Path.join(__dirname, './file/smallimage.png'); | ||
var stats = Fs.statSync(path); | ||
var form = new FormData(); | ||
form.append('file1', Fs.createReadStream(path)); | ||
form.append('file2', Fs.createReadStream(path)); | ||
form.headers = form.getHeaders(); | ||
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) { | ||
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); | ||
done(); | ||
}); | ||
}); | ||
it('parses multiple larger files', function (done) { | ||
var path = Path.join(__dirname, './file/image.jpg'); | ||
var stats = Fs.statSync(path); | ||
var form = new FormData(); | ||
form.append('file1', Fs.createReadStream(path)); | ||
form.append('file2', Fs.createReadStream(path)); | ||
form.headers = form.getHeaders(); | ||
Subtext.parse(form, null, { parse: true, output: 'file' }, function (err, parsed) { | ||
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(); | ||
}); | ||
}); | ||
it('parses multiple files while waiting for last file to be written', { parallel: false }, function (done) { | ||
@@ -1172,3 +1260,2 @@ | ||
expect(err).to.not.exist(); | ||
var fileContents = Fs.readFileSync(path); | ||
expect(parsed.payload.my_file.name).to.equal('subtext'); | ||
@@ -1237,3 +1324,2 @@ done(); | ||
var path = Path.join(__dirname, './file/image.jpg'); | ||
var stats = Fs.statSync(path); | ||
var fileStream = Fs.createReadStream(path); | ||
@@ -1240,0 +1326,0 @@ var fileContents = Fs.readFileSync(path); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
249366
11
1463
34
2