Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Removed http header Accept by default

#1053

This patch fix the 406 Not Acceptable http error when working with the YouTube API.


http = Net::HTTP.new("gdata.youtube.com")

response = http.head('/feeds/api/videos?vq=rails', 'Accept' => 'application/xml')
response.code # => "406"

response = http.head('/feeds/api/videos?vq=rails')
response.code # => "200"

See http://groups.google.com/group/r... for details.

Reported by Edgar Suarez · September 15th, 2008 @ 06:27 PM

State: committed
Milestone: none
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Michael Koziarski
    Michael Koziarski
    • Tag changed from accept, activeresource, formats, header, patch, xml, youtube to accept, activeresource, formats, header, patch, xml, youtube

    So what is it about this that breaks the youtube api?

    You should be able to override the Accept header to contain the values supported by the api? The 406 reply you're receiving is just because gdata can't reply with that content type:

    406 = "Not Acceptable",

    September 16th, 2008 @ 10:23 AM

  2. Edgar Suarez
    Edgar Suarez

    Yes, it's supposed to be able to change the accept header but it just ignores my header because the method overrides it:

    
    #ActiveResource::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
    

    So even when I do:

    
    connection.get('/feeds/api/videos?vq=rails', {'Accept' => 'application/xhtml+xml'})
    # or any other mime type
    

    It is overridden with 'application/xml' which is the default mime for the get method.

    I've been thinking and actually there should be a cleaner way to fix this (maybe a reverse update), but I just made the patch in hurry in the meantime.

    Regards.

    September 17th, 2008 @ 01:31 AM

  3. Michael Koziarski
    Michael Koziarski
    • Assigned user set to Michael Koziarski
    • Milestone changed from 2.x to 2.1.2

    OK, so if you can upload a new version of this patch which:

    1) Includes a test case (use mocha if it's easier) 2) Does a reverse merge instead

    I think we'll be good to go

    September 17th, 2008 @ 10:45 AM

  4. Edgar Suarez
    Edgar Suarez

    Ok, so good so far... here is the cleaner patch with the proper test using mocha.

    Hope it's good enough to go.

    September 17th, 2008 @ 09:29 PM

  5. Michael Koziarski
    Michael Koziarski
    • Milestone cleared.

    I've reverted the change that introduced this from 2-1-stable, so this now needs to be addressed in 2.2.0

    September 18th, 2008 @ 10:01 AM

  6. rbpandey
    rbpandey

    This seems to have been applied to trunk already. Can this be marked as resolved?

    September 23rd, 2008 @ 08:28 PM

  7. Michael Koziarski
    Michael Koziarski
    • State changed from new to committed

    September 23rd, 2008 @ 08:30 PM