Permalink
Browse files

Allow bodyDecoder / connect-form to coexist

  • Loading branch information...
1 parent f69596d commit e2924edd9b4a12f8f38d36e1918bc780d295569c @tj tj committed Jul 27, 2010
Showing with 23 additions and 1 deletion.
  1. +2 −1 lib/connect-form.js
  2. +21 −0 test/form.test.js
View
@@ -76,7 +76,8 @@ module.exports = function(options){
*/
function formRequest(req){
- return (req.method === 'POST'
+ return req.body === undefined
+ && (req.method === 'POST'
|| req.method === 'PUT')
&& (req.headers['content-type'].indexOf('multipart/form-data') >= 0
|| req.headers['content-type'].indexOf('urlencoded') >= 0);
View
@@ -124,4 +124,25 @@ exports['test urlencoded'] = function(assert){
assert.response(server,
{ url: '/', method: 'POST', data: body, headers: headers },
{ body: '{"thanks":"felix","for":"the","cool":"lib"}{}' });
+};
+
+exports['test bodyDecoder'] = function(assert){
+ var server = connect.createServer(
+ connect.bodyDecoder(),
+ form(),
+ function(req, res){
+ res.writeHead(200, {});
+ res.end(JSON.stringify(req.body));
+ }
+ );
+
+ var headers = {
+ 'Content-Type': 'application/x-www-form-urlencoded'
+ };
+
+ var body = 'foo=bar';
+
+ assert.response(server,
+ { url: '/', method: 'POST', data: body, headers: headers },
+ { body: '{"foo":"bar"}' });
};

0 comments on commit e2924ed

Please sign in to comment.