This is not obvious, but it is effective.
Solution:
match('/',:query_string=>/.+/).defer_to do |request, params|
raise Merb::ControllerExceptions::NotAcceptable,
"Query String Unknown: #{request.query_string}"
end
Explanation:
In order to trigger a 406 error we need to raise Merb::ControllerExceptions::NotAcceptable
but if we do this while setting up the routes it helps exactly no one. Instead we need to wait until Merb is handling the request. this is what the defer_to
block does. When the request comes in we raise the error and it is caught and handled just as it would be if we through this error from a controller.
Problems
One of the goals of my original question was to avoid having to go through all of the dispatching overhead. Instead this solution is dispatched through the exceptions controller which more computationally expensive then [406,{'content-type'=>'text/plain},['406 Not Acceptable']]