On Jun 23, 2011, at 3:47 PM, Tomas Von Veschler (JIRA) wrote:

> 
>    [ 
> https://issues.apache.org/jira/browse/DTACLOUD-53?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13053856#comment-13053856
>  ] 
> 
> Tomas Von Veschler commented on DTACLOUD-53:
> --------------------------------------------
> 
> A curious finding, if I use the same User-Agent as Chrome, the content of the 
> response changes:
> 
> $ curl --url http://192.168.0.194/api/hardware_profiles --show-error --header 
> "Accept: application/json" -s -v --header "User-Agent:Mozilla/5.0 (X11; Linux 
> x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.74" 2>&1 | egrep 
> '(Accept|Content-Type)'
>> Accept: application/json
> < Content-Type: text/html;charset=utf-8

Yes, I think this has to do with our respond_to library 
(lib/sinatra/respond_to.rb):

        def is_chrome?
          true if env['HTTP_USER_AGENT'] =~ /Chrome/
        end

Then:

        if rack_accept.media_type.to_s.strip.eql?('Accept:')
          format :xml
        elsif is_chrome?
          format :html
        else
          format 
lookup_format_from_mime(rack_accept.best_media_type(accept_to_array))
        end

I think the fix for this would be to check if Accept is application/json and 
return JSON.
This 'workaround' was bought in since Chrome was acting as IE in this way. It 
sends 'application/xml'
first before html.

I'll take a look and test it again on different browser and fix it. Thanks for 
reporting this!

  -- Michal


> 
> This is also preventing XMLHttpRequest calls from Chrome to work, while it's 
> working on Firefox.
> 
>> Wrong content type selected if multiple media types are supplied
>> ----------------------------------------------------------------
>> 
>>                Key: DTACLOUD-53
>>                URL: https://issues.apache.org/jira/browse/DTACLOUD-53
>>            Project: DeltaCloud
>>         Issue Type: Bug
>>         Components: Server
>>           Reporter: Tomas Von Veschler
>>           Assignee: David Lutterkort
>>           Priority: Minor
>> 
>> When setting the Accept header as for example: application/json, */* , seems 
>> that */* is picked up and XML content is returned instead of JSON. This 
>> doesn't follow the HTTP RFC 
>> (http://tools.ietf.org/html/rfc2616#section-14.1):
>> Media ranges can be overridden by more specific media ranges or
>>   specific media types. If more than one media range applies to a given
>>   type, the most specific reference has precedence. For example,
>>       Accept: text/*, text/html, text/html;level=1, */*
>>   have the following precedence:
>>       1) text/html;level=1
>>       2) text/html
>>       3) text/*
>>       4) */*
>> How to test it:
>> $ curl --url http://192.168.0.194/api/hardware_profiles --show-error 
>> --header "Accept: application/json, */*" -s -v 2>&1 | egrep 
>> '(Accept|Content-Type)'
>>> Accept: application/json, */*
>> < Content-Type: application/xml;charset=utf-8
>> $ curl --url http://192.168.0.194/api/hardware_profiles --show-error 
>> --header "Accept: application/json" -s -v 2>&1 | egrep 
>> '(Accept|Content-Type)'
>>> Accept: application/json
>> < Content-Type: application/json;charset=utf-8
>> This causes problems to all jQuery users, as it sends 
>> "Accept:application/json, text/javascript, */*"
> 
> --
> This message is automatically generated by JIRA.
> For more information on JIRA, see: http://www.atlassian.com/software/jira
> 
> 

Reply via email to