Comparing version 1.0.1 to 1.0.2
@@ -5,3 +5,2 @@ // Load modules | ||
var Querystring = require('querystring'); | ||
var Formidable = require('formidable'); | ||
var Boom = require('boom'); | ||
@@ -46,13 +45,2 @@ var Utils = require('./utils'); | ||
var clientTimeout = request.server.settings.timeout.client; | ||
var clientTimeoutId = null; | ||
if (clientTimeout) { | ||
clientTimeout -= Date.now() - request._timestamp; | ||
clientTimeoutId = setTimeout(function () { | ||
finish(Boom.clientTimeout('Client is taking too long to send request')); | ||
}, clientTimeout); | ||
} | ||
// Return only once from events | ||
@@ -70,2 +58,15 @@ | ||
// Setup client timeout | ||
var clientTimeout = request.server.settings.timeout.client; | ||
var clientTimeoutId = null; | ||
if (clientTimeout) { | ||
clientTimeout -= Date.now() - request._timestamp; | ||
clientTimeoutId = setTimeout(function () { | ||
finish(Boom.clientTimeout('Client is taking too long to send request')); | ||
}, clientTimeout); | ||
} | ||
// Read incoming body | ||
@@ -180,8 +181,26 @@ | ||
var contentType = (headers && headers['content-type']) || 'application/json'; // Defaults to 'application/json' | ||
var mime = contentType.split(';')[0].trim().toLowerCase(); | ||
var contentTypeParts = contentType.split(';'); | ||
var mime = contentTypeParts[0].trim().toLowerCase(); | ||
// Parse content type attributes | ||
// 1 - name 2 - value | ||
var attributesRegx = /(?:\s*;\s*([\w\!#\$%&'\*\+\-\.\^`\|~]+)\=((?:[\w\!#\$%&'\*\+\-\.\^`\|~]+)|(?:"(?:[^"\\]|\\.)*")))/g; | ||
var attributes = {}; | ||
if (contentTypeParts[1]) { | ||
var verify = contentTypeParts[1].replace(attributesRegx, function ($0, $1, $2) { | ||
attributes[$1] = $2; | ||
return ''; | ||
}); | ||
if (verify !== '') { | ||
return callback(Boom.badRequest('Invalid content-type header format')); | ||
} | ||
} | ||
// Text | ||
if (mime.match(/^text\/.+$/)) { | ||
return callback(payload.toString('utf-8')); | ||
return callback(null, payload.toString('utf-8')); | ||
} | ||
@@ -213,6 +232,6 @@ | ||
if (mime === 'multipart/form-data') { | ||
if (false) { //mime === 'multipart/form-data') { | ||
var data = {}; | ||
var form = new Formidable.IncomingForm(); | ||
var form = new Multiparty.Form(); | ||
@@ -219,0 +238,0 @@ var processData = function (name, val) { |
@@ -5,3 +5,3 @@ { | ||
"homepage": "http://hapijs.com", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -8,0 +8,0 @@ "contributors": [ |
@@ -305,4 +305,10 @@ // Load modules | ||
var textHandler = function (request) { | ||
request.reply(request.payload + '+456'); | ||
}; | ||
var server = new Hapi.Server('localhost', 0, { timeout: { client: 50 } }); | ||
server.route({ method: 'POST', path: '/', config: { handler: handler, payload: 'parse' } }); | ||
server.route({ method: 'POST', path: '/text', config: { handler: textHandler } }); | ||
server.route({ method: '*', path: '/any', handler: handler }); | ||
@@ -429,20 +435,8 @@ | ||
var options = { | ||
hostname: 'localhost', | ||
port: server.info.port, | ||
path: '/?x=5', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'text/plain', | ||
'Content-Length': '18' | ||
} | ||
}; | ||
server.inject({ method: 'POST', url: '/text', payload: 'testing123', headers: { 'content-type': 'text/plain' } }, function (res) { | ||
var req = Http.request(options, function (res) { | ||
expect(res.statusCode).to.equal(200); | ||
expect(res.result).to.equal('testing123+456'); | ||
done(); | ||
}); | ||
req.end('{ "key": "value" }'); | ||
}); | ||
@@ -449,0 +443,0 @@ }); |
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
836318
174
13616