api/async: add support for content negotiation
For the content negotiation to work, we expect handler functions to return straight data structures instead of Response objects so we can handle the serialization in the "main" middleware (error_middleware, which should probably be renamed).
It should still work with server handler implementations that do produce Response object, but without the content negotitation feature available then.
Related to #1871
Migrated from D1688 (view on Phabricator)