codegangsta/martini-contrib — pull request #118 by beatrichartz (2014-02-03 19:19:22+00:00)
Title: Status Codes 422 for Validation Errors and 400 for Badly formed Requests

It is great to have the middleware validate the form for us and have Binding return the form errors directly without the request touching ground.

Returning appropriate status codes on errors is the right thing to do, and I'm concerned that returning status code 400 Bad Request on validation errors is confusing insofar that it tells the requester that request syntax is malformed - returning [422 Unprocessable Entity](https://tools.ietf.org/html/rfc2518#page-60) would be a lot clearer in this case.

In this PR there is added support to distinguish those two cases. In order to be able to revoke badly formed Multipart Form Requests right off the bat, there is also an added Binding for Multipart forms.

There is one note to add about URL-Encoded Form Values: ReadForm / ReadMultipartForm does not validate request encoding ([returns nil as an error](https://code.google.com/p/go/issues/detail?id=6334)). Validating multipart forms is done via a multipart reader, but validating url-encoded forms for formatting errors would add considerable overhead, and also an empty url-encoded request could be interpreted as absence of all values, so in these cases let's return 422.

Hope it's useful!