Reading header data in Ruby on Rails

前端 未结 3 592
粉色の甜心
粉色の甜心 2020-12-28 11:19

I am making an API where in the access token for Facebook login will be sent in through header data.

How do I read this data from the header?

相关标签:
3条回答
  • 2020-12-28 11:55

    To get hash of actual http headers use @_headers in controller.

    0 讨论(0)
  • 2020-12-28 12:02
    request.headers["Content-Type"] # => "text/plain"
    

    replace "Content-Type" with the name of the header that you want to read.

    Update for Rails 4.2

    There are 2 ways to get them in Rails 4.2: Old way (still working):

    request.headers["Cookie"]
    

    New way:

    request.headers["HTTP_COOKIE"]
    

    To get a Hash with all headers of the request.

    request.headers
    
    0 讨论(0)
  • 2020-12-28 12:05

    Rails now attaches HTTP_ to the header as well as converting it to all caps so it would now be:

    request.headers["HTTP_CONTENT_TYPE"]
    
    0 讨论(0)
提交回复
热议问题