edgarjs
2008-Sep-15  07:32 UTC
[ActiveResource] Sets Accept header to ''application/xml'' by default
I made a plugin for the YouTube API back in Rails'' version 2.0.2 and
it was working good enough. Now I decided to try it in version 2.1.1
and it returns a 406 http error always.
So I tracked the issue and found that from version 2.1.0 to 2.1.1
there was a change in the
ActiveResource::Connection#build_request_headers method that updates
the request''s header to "application/xml" by default with the
GET http
method.
I really apologize for my english, I think it will be more clear with
an example:
Rails v 2.1.0:
module ActiveResource
  class Connection
    #.....
    def build_request_headers(headers)
      authorization_header.update(default_header).update(headers)
    end
  end
end
Rails v 2.1.1:
module ActiveResource
  class Connection
    #.....
    def build_request_headers(headers, http_method=nil)
 
authorization_header.update(default_header).update(headers).update(http_format_header(http_method))
    end
    def http_format_header(http_method)
      {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type}
    end
  end
end
So it''s like if we were doing
 
connection.get(''http://gdata.youtube.com/feeds/api/videos?vq=rails'',
''Accept'' => ''application/xml'')
and this causes a 406 http error always.... at least from YouTube API
Regards.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2008-Sep-15  09:38 UTC
Re: [ActiveResource] Sets Accept header to ''application/xml'' by default
On Mon, Sep 15, 2008 at 9:32 AM, edgarjs <edgar.js@gmail.com> wrote:> > I made a plugin for the YouTube API back in Rails'' version 2.0.2 and > it was working good enough. Now I decided to try it in version 2.1.1 > and it returns a 406 http error always. > > So I tracked the issue and found that from version 2.1.0 to 2.1.1 > there was a change in the > ActiveResource::Connection#build_request_headers method that updates > the request''s header to "application/xml" by default with the GET http > method. > > I really apologize for my english, I think it will be more clear with > an example: > > > Rails v 2.1.0: > > module ActiveResource > class Connection > #..... > def build_request_headers(headers) > authorization_header.update(default_header).update(headers) > end > end > end > > > Rails v 2.1.1: > > module ActiveResource > class Connection > #..... > def build_request_headers(headers, http_method=nil) > > authorization_header.update(default_header).update(headers).update(http_format_header(http_method)) > end > > def http_format_header(http_method) > {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type} > end > end > end > > So it''s like if we were doing > > connection.get(''http://gdata.youtube.com/feeds/api/videos?vq=rails'', > ''Accept'' => ''application/xml'') > > and this causes a 406 http error always.... at least from YouTube API > > > Regards.This would appear to be caused by: http://github.com/rails/rails/commit/caabe228bc6c6e920043334d717e72093559e118 Could you submit a patch which includes a failing test case? -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
edgarjs
2008-Sep-15  17:33 UTC
Re: [ActiveResource] Sets Accept header to ''application/xml'' by default
Well, so this is my first patch I make. Hope I did it ok. I had some problems with the tests since http mock does not a true call to the remote service, I did tests creating a bare http instance that demonstrates this error. http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1053-removed-http-header-accept-by-default Regards. On Sep 15, 4:38 am, "Michael Koziarski" <mich...@koziarski.com> wrote:> On Mon, Sep 15, 2008 at 9:32 AM, edgarjs <edgar...@gmail.com> wrote: > > > I made a plugin for the YouTube API back in Rails'' version 2.0.2 and > > it was working good enough. Now I decided to try it in version 2.1.1 > > and it returns a 406 http error always. > > > So I tracked the issue and found that from version 2.1.0 to 2.1.1 > > there was a change in the > > ActiveResource::Connection#build_request_headers method that updates > > the request''s header to "application/xml" by default with the GET http > > method. > > > I really apologize for my english, I think it will be more clear with > > an example: > > > Rails v 2.1.0: > > > module ActiveResource > > class Connection > > #..... > > def build_request_headers(headers) > > authorization_header.update(default_header).update(headers) > > end > > end > > end > > > Rails v 2.1.1: > > > module ActiveResource > > class Connection > > #..... > > def build_request_headers(headers, http_method=nil) > > > authorization_header.update(default_header).update(headers).update(http_format_header(http_method)) > > end > > > def http_format_header(http_method) > > {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type} > > end > > end > > end > > > So it''s like if we were doing > > > connection.get(''http://gdata.youtube.com/feeds/api/videos?vq=rails'', > > ''Accept'' => ''application/xml'') > > > and this causes a 406 http error always.... at least from YouTube API > > > Regards. > > This would appear to be caused by: > > http://github.com/rails/rails/commit/caabe228bc6c6e920043334d717e7209... > > Could you submit a patch which includes a failing test case? > > -- > Cheers > > Koz--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---