Allows upstream middleware to consume and manipulate message body and still use bodyParser. #356

Closed
wants to merge 1 commit into
from

2 participants

@ryanrolds

Currently, if an upstream middleware consumes http(s).ServerRequest's message body events and valid json/form header are set then bodyParser will never complete it's attempt at getting the message body. This update allows earlier middleware to set req.rawBody, which will be used instead, avoiding the hang and allowing consumption and manipulation of the message body prior to parsing by bodyParser.

I noticed that as of the 10th, rawBody was removed. If desired, rawBody could be unset by bodyParser after parsing.

@tj
Sencha Labs member
tj commented Aug 28, 2011

I dont think we really need to complicate it, it's easy enough to just use JSON.parse etc directly (though if you wanted to you could still use connect.bodyParser.parse[mime]

@ryanrolds

The idea is to consolidate concerns. Yes, one could call the needed parsers directly, but either you end up doing ALL the parsing in the new middleware or you end up with parsing happening in multiple locations. Why write/maintain your own parsing middleware when connect provides a great one already?

@ryanrolds ryanrolds closed this Sep 4, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment