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.

head method attempts to camelcase headers

#5636

I am using Rails 3 on Ruby 1.9.2.

This call:

head 401, 'WWW-Authenticate' => Rack::OpenID.build_header(:identifier => params[:openid_identifier])

actually returns:

"{"Www-Authenticate"=>"OpenID identifier=\"https://www.google.com/accounts/o8/id\"", "Content-Type"=>"text/html; charset=utf-8", "Cache-Control"=>"no-cache"}"

Notice the "Www-Authenticate" which of course does not work with rack-openid, which is correctly looking for WWW-Authenticate.

This call:

  response.headers['WWW-Authenticate'] = Rack::OpenID.build_header(:identifier => params[:openid_identifier])
  head 401

correctly sets the header and does not change the case of the letters.

Reported by Seth Ladd · September 15th, 2010 @ 11:05 PM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Maxim Chernyak
    Maxim Chernyak

    +1 reproduced exactly the same way.

    September 18th, 2010 @ 08:26 AM

  2. Maxim Chernyak
  3. Rohit Arondekar
    Rohit Arondekar
    • Milestone cleared.
    • State changed from new to open
    • Importance changed from to Low

    September 18th, 2010 @ 08:28 AM

  4. Maxim Chernyak
    Maxim Chernyak

    Looks like we need to avoid capitalize here: http://github.com/rails/rails/blob/master/actionpack/lib/action_con...

    capitalize not only upcases first letter, but also downcases the rest of them. Making a patch to avoid capitalize.

    September 18th, 2010 @ 08:53 AM

  5. Rohit Arondekar
    Rohit Arondekar
    • Assigned user set to José Valim

    September 18th, 2010 @ 08:57 AM

  6. Maxim Chernyak
    Maxim Chernyak
    • Tag changed from rails 3.0.0 to rails 3.0.0, patch

    Here's patch + test against master.

    September 18th, 2010 @ 09:15 AM

  7. Seth Ladd
    Seth Ladd

    Thanks! That should help a ton.

    September 18th, 2010 @ 05:13 PM

  8. José Valim
    José Valim

    Looks good, but couldn't we do something like this instead:

    headers[key.to_s.dasherize.split("-").each { |v| v[0] = v[0].upcase }.join("-")] = value.to_s

    Seems faster and simpler!

    September 18th, 2010 @ 07:20 PM

  9. Maxim Chernyak
    Maxim Chernyak

    @Jose

    Almost right. v[0] = v[0].chr.upcase. Will fix now, sec.

    September 18th, 2010 @ 07:25 PM

  10. José Valim
    José Valim

    One question. Why do we need .chr? It worked fine without it on 1.8.7 and 1.9.2.

    September 18th, 2010 @ 07:32 PM

  11. Maxim Chernyak
    Maxim Chernyak

    Strange.

    ruby-1.8.7-p302 > v = 'foo'
     => "foo" 
    ruby-1.8.7-p302 > v[0] = v[0].upcase
    NoMethodError: undefined method `upcase' for 102:Fixnum
            from (irb):2
    

    September 18th, 2010 @ 07:35 PM

  12. José Valim
    José Valim

    Sorry, it was my bad. You are correct sir!

    September 18th, 2010 @ 07:37 PM

  13. Maxim Chernyak
    Maxim Chernyak

    Happens. :) I don't know why I didn't do first char assignment in the first place, thanks.

    Here's the new patch.

    September 18th, 2010 @ 07:39 PM

  14. Repository
    Repository
    • State changed from open to resolved

    (from [20685d07ab5853457e1d11467f22ed42568e20f4]) Fix header capitalization by explicitly upcasing first letter of every word, and avoiding capitalize. [#5636 head method attempts to camelcase headers state:resolved] http://github.com/rails/rails/commit/20685d07ab5853457e1d11467f22ed...

    September 18th, 2010 @ 07:50 PM

  15. Jeremy Kemper
  16. Ryan Bigg
    Ryan Bigg
    • Tag changed from rails 3.0.0, sheepskin boots, patch to patch rails 3.0.0

    Automatic cleanup of spam.

    October 16th, 2010 @ 02:22 AM