0

Is it possible to access response headers of an HTML request sent to the browser via ruby (in controllers)?

What I am doing? I am trying to authenticate a login request using devise and devise-jwt in a rails app. After successful authentication I am assigned an Authorization token in response headers and redirected to a after_sign_in_path. Now on browser I can see the token being received, however I also need the same token issued in the controller action before it goes to the browser.

Upon parsing/logging response headers(response.headers) in the controller action(responsible for rendering the same view), i don't see Authorization key at all.

Alternative: Tried using javascript but as it turns out you can only parse response headers of a request initiated by javascript. This link states the same

Is there a way i can achieve this and not resort to using ajax request method?

cop
  • 93
  • 3
  • 10

1 Answers1

0

An ActionCongtroller::Base#response object is created by Rails and contains all the information of the HTTP response being built by the controller. This is an instance of ActionDispatch::Response. There are various methods for accessing and interacting with the response headers. response.headers is where you would want to add custom response data.

Tom
  • 1,311
  • 10
  • 18
  • Hey, thanks but i have been using the same object to find the token, however token is absent in the object but it always reaches the browser – cop Jan 19 '19 at 10:16