[ActiveResource] Sets Accept header to 'application/xml' by default

449 views
Skip to first unread message

edgarjs

unread,
Sep 15, 2008, 3:32:55 AM9/15/08
to Ruby on Rails: Core
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.

Michael Koziarski

unread,
Sep 15, 2008, 5:38:14 AM9/15/08
to rubyonra...@googlegroups.com

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

edgarjs

unread,
Sep 15, 2008, 1:33:57 PM9/15/08
to Ruby on Rails: Core
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:
> http://github.com/rails/rails/commit/caabe228bc6c6e920043334d717e7209...
Reply all
Reply to author
Forward
0 new messages