scalatra/scalatra — pull request #397 by duncanol (2014-05-29 21:14:27+00:00)
Title: Honouring request's Content-Type header when parsing params and request body for command object

Wanting to test content negotiation whereby a request could be sent as a form post (i.e. with a Content-Type request header of "application/x-www-form-urlencoded") but with the user-agent requesting that the response format be json (i.e. with an Accept request header of "application/json") I was finding that the command object could not be parsed from the submitted form data because JacksonJsonParsing.bindCommand was assuming the request's format was defined by the Accept header rather than the Content-Type header.

This meant that the command object failed to populate from the posted form values because it was looking for a JSON string, and therefore returned a 400.

My change is to firstly look to see if the request has specified a Content-Type header and, if so, look up the corresponding format from it. Failing that it falls back to the original behaviour of JacksonJsonParsing.bindCommand.

Thanks,
Duncan