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.

ActiveResource 'head' request sends headers with a nil key

#1223

I've noticed that ActiveResource.exists? doesn't seem to be working correctly. Here's the backtrace I'm getting:

NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.downcase
 from /usr/local/lib/ruby/1.8/net/http.rb:1261:in `key?'
 from /usr/local/lib/ruby/1.8/net/http.rb:1150:in `initialize_http_header'
 from /usr/local/lib/ruby/1.8/net/http.rb:1149:in `each'
 from /usr/local/lib/ruby/1.8/net/http.rb:1149:in `initialize_http_header'
 from /usr/local/lib/ruby/1.8/net/http.rb:1481:in `initialize'
 from /usr/local/lib/ruby/1.8/net/http.rb:1597:in `initialize'
 from /usr/local/lib/ruby/1.8/net/http.rb:810:in `new'
 from /usr/local/lib/ruby/1.8/net/http.rb:810:in `head'
 from /Users/elliot/Sites/localhost/htdocs/proj/work/store/vendor/rails/activeresource/lib/active_resource/connection.rb:152:in `send'
 from /Users/elliot/Sites/localhost/htdocs/proj/work/store/vendor/rails/activeresource/lib/active_resource/connection.rb:152:in `request'
 from /Users/elliot/Sites/localhost/htdocs/proj/work/store/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:8:in `realtime'
 from /Users/elliot/Sites/localhost/htdocs/proj/work/store/vendor/rails/activeresource/lib/active_resource/connection.rb:152:in `request'
 from /Users/elliot/Sites/localhost/htdocs/proj/work/store/vendor/rails/activeresource/lib/active_resource/connection.rb:140:in `head'
 from /Users/elliot/Sites/localhost/htdocs/proj/work/store/vendor/rails/activeresource/lib/active_resource/base.rb:554:in `exists?'

I believe this happens because when ARes does a HEAD request, it's sending a headers hash that contains a key which is nil (because it's trying to send a format header along but there's no header defined for HEAD requests in ARes::Connection::HTTP_FORMAT_HEADER_NAMES). I've attached a failing test case that pinpoints this behavior. Is this normal?

Reported by Elliot Winkler · October 16th, 2008 @ 12:53 AM

State: stale
Milestone: 3.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Elliot Winkler
    Elliot Winkler
    • Tag changed from activeresource to activeresource, patch

    Here's a patch that fixes the issue for me.

    October 16th, 2008 @ 02:54 PM

  2. FiXato
    FiXato

    In revision 16b9a554db7e1bf3f5f224cdc5b4d27480e053ff correct http headers have been added per http method type, but the header for the HEAD request was ommitted. This could also be fixed by making head sent a :head method:

    November 17th, 2008 @ 10:49 AM

  3. Elliot Winkler
    Elliot Winkler

    That actually looks better, mine was kind of a hack. I guess you should add tests?

    November 18th, 2008 @ 04:26 AM

  4. Pratik
    Pratik
    • Assigned user set to Pratik
    • State changed from new to incomplete

    Looks good. But missing tests. Will apply once we have a patch with tests.

    Thanks!

    March 7th, 2009 @ 03:09 PM

  5. Joshua Bates
    Joshua Bates

    Here's a patch with tests. Using a Net::HTTP object in the test seems brittle, but I'm not sure there are any better choices outside of leaving it uncovered.

    March 21st, 2009 @ 06:42 AM

  6. dirkbj
    dirkbj

    In a REST environment, HEAD is most closely associated with a GET request, but the request does not return content in the response body. Is putting :head => 'Content-Type' in the HTTP_FORMAT_HEADER_NAMES hash really the best option when :head is not sending any content as a PUT or POST would? I am of the opinion the first patch is more in the spirit of REST.

    June 19th, 2009 @ 03:15 AM

  7. Pratik
    Pratik
    • State changed from incomplete to open

    June 19th, 2009 @ 08:33 AM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  9. Santiago Pastorino
    Santiago Pastorino
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:04 PM

  10. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:05 PM