Accessing headers from Sinatra

前端 未结 2 511
滥情空心
滥情空心 2021-02-08 06:00

I am trying to access the headers in a filter in sinatra. My request includes the header \"HTTP_AUTH\", however I can\'t access it. My filter is

before do
    ha         


        
2条回答
  •  梦谈多话
    2021-02-08 06:26

    I just wanted to add that if you use headers it will not show custom headers. For example, I set up a custom header named X-CSRF-Token which I send on every AJAX request, and this one won't show up in that hash. If you need to access custom headers, you will find them through request.env like:

    post '/' do
      header_token = request.env["HTTP_X_CSRF_TOKEN"]
    end
    

    (Notice how rack changes X-CSRF-Token to HTTP_X_CSRF_TOKEN)

提交回复
热议问题