deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Lutterkort <lut...@redhat.com>
Subject Re: [PATCH] CIMI - slight hack to prefer content_type of xml when CIMI frontend is being used (and client specifies this as accepted type)
Date Tue, 13 Mar 2012 21:11:12 GMT
On Tue, 2012-03-13 at 18:17 +0200, marios@redhat.com wrote:
> From: marios <marios@redhat.com>
> 
> HTML views for CIMI are being phased out...
> 
> Signed-off-by: marios <marios@redhat.com>
> ---
>  server/lib/sinatra/rack_accept.rb |   10 +++++++---
>  1 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/server/lib/sinatra/rack_accept.rb b/server/lib/sinatra/rack_accept.rb
> index b576307..0f179ea 100644
> --- a/server/lib/sinatra/rack_accept.rb
> +++ b/server/lib/sinatra/rack_accept.rb
> @@ -77,9 +77,13 @@ module Rack
>              self[type] = handler
>            end
>            yield wants
> -          @media_type = accepting_formats.to_a.sort { |a,b| a[1]<=>b[1] }.reverse.select
do |format, priority|
> -            wants.keys.include?(format) == true
> -          end.first
> +          if ENV['API_FRONTEND'] == "cimi"
> +            @media_type = (accepting_formats.has_key?(:xml) ? [:xml, accepting_formats[:xml]]
: nil)
> +          else
> +            @media_type ||= accepting_formats.to_a.sort { |a,b| a[1]<=>b[1] }.reverse.select
do |format, priority|
> +              wants.keys.include?(format) == true
> +            end.first
> +          end

Doesn't this break content negotiation ? We can only ignore other
formats if q=1 for application/xml (implicitly or explicitly) In
particular, wouldn't the above break with an Accept header of
'application/json, application/xml;q=0.9' ?

Also, it would be cleaner if the format preference was encoded in each
server.rb (e.g., as an array constant) AFAIK, self at this point is the
Sinatra app.

David



Mime
View raw message