Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added urlencoded support

  • Loading branch information...
commit 2dd93e3e0585ad7babe9defcf0e3245b7bc05153 1 parent ef23a54
@tj tj authored
Showing with 9 additions and 10 deletions.
  1. +7 −8 index.js
  2. +2 −2 test/{multipart.test.js → form.test.js}
View
15 index.js
@@ -13,7 +13,7 @@ var utils = require('connect/utils'),
formidable = require('./support/formidable');
/**
- * Setup multipart with the given `options`.
+ * Setup form with the given `options`.
*
* Options:
*
@@ -26,12 +26,10 @@ var utils = require('connect/utils'),
* @api public
*/
-// TODO: urlencoded too
-
-module.exports = function multipart(options){
+module.exports = function(options){
options = options || {};
return function(req, res, next){
- if (multipartRequest(req)) {
+ if (formRequest(req)) {
var form = req.form = new formidable.IncomingForm;
utils.merge(form, options);
form.onComplete = function(){};
@@ -44,15 +42,16 @@ module.exports = function multipart(options){
};
/**
- * Check if `req` is a multipart request.
+ * Check if `req` is a valid form request.
*
* @param {IncomingMessage} req
* @return {Boolean}
* @api private
*/
-function multipartRequest(req){
+function formRequest(req){
return (req.method === 'POST'
|| req.method === 'PUT')
- && req.headers['content-type'].indexOf('multipart/form-data') >= 0;
+ && (req.headers['content-type'].indexOf('multipart/form-data') >= 0
+ || req.headers['content-type'].indexOf('urlencoded') >= 0);
}
View
4 test/multipart.test.js → test/form.test.js
@@ -122,6 +122,6 @@ exports['test urlencoded'] = function(assert){
var body = 'thanks=felix&for=the&cool=lib';
assert.response(server,
- { url: '/', data: body, headers: headers },
- { body: '{"thanks":"felix","for":"the","cool":"lib"}' });
+ { url: '/', method: 'POST', data: body, headers: headers },
+ { body: '{"thanks":"felix","for":"the","cool":"lib"}{}' });
};
Please sign in to comment.
Something went wrong with that request. Please try again.