If you're up against the wall and have no way of changing the completely broken client, you might want to try and gracefully recover here.
Usually you can add a filter in your config.ru
file for your application that will re-write the damaged headers:
use TinCanFixer
Then you write a Rack handler:
class TinCanFixer
def initialize(app)
@app = app
end
def call(env)
case (env["CONTENT_TYPE"])
when "application/json"
# Check that it's actually JSON
unless (env["rack.input"].match(/^\{\[/))
env["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
end
end
@app.call(env)
end
end
Untested but should, in principle, sniff out non-JSON content and reassign the rack.input
header which dictates content type.