Hi Marios,
On Wed, 2012-03-14 at 13:22 +0200, [email protected] wrote:
> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
> index 6cd845e..653c8c8 100644
> --- a/server/lib/cimi/server.rb
> +++ b/server/lib/cimi/server.rb
> @@ -35,6 +35,7 @@ use Rack::Date
> use Rack::CIMI
>
> configure do
> + set :cimi_preferred_formats, [:xml, :json]
> set :root_url, "/cimi"
> set :views, File::join($top_srcdir, 'views', 'cimi')
> set :public_folder, File::join($top_srcdir, 'public')
>
> diff --git a/server/lib/sinatra/rack_accept.rb
> b/server/lib/sinatra/rack_accept.rb
> index 2ad52c7..7b2f200 100644
> --- a/server/lib/sinatra/rack_accept.rb
> +++ b/server/lib/sinatra/rack_accept.rb
> @@ -77,10 +77,11 @@ module Rack
> self[type] = handler
> end
> yield wants
> - if ENV['API_FRONTEND'] == "cimi"
> - @media_type = (accepting_formats.has_key?(:xml) ? [:xml,
> accepting_formats[:xml]] : nil)
> + if (ENV['API_FRONTEND'] == "cimi" &&
> accepting_formats.has_key?(:html) &&
> + (accepting_formats.keys &
> settings.cimi_preferred_formats).length > 0 )
My comment about making desirable formats a constant was meant so that
we can get rid of the ENV['API_FRONTEND'] == "cimi" test.
Come to think of it, if I write
respond_to do |fmt|
fmt.xml { .. stuff .. }
fmt.json { .. stuff .. }
end
rack_accept should only ever choose XML or JSON, without any additional
logic; in particular, it should never choose HTML. If rack_accept
behaves differently, there's a bug in how it does content negotiation.
To be clear, with the above respond_to, we should
* only consider XML or JSON for the response, regardless what else
is in the Accept header
* prefer XML over JSON if the Accept header has them at the same
priority (q value)
David