mercredi 29 mars 2023

How to pass header X-Request-Start to Rails app under Apache + Passenger

I need to pass header X-Request-Start to my Rails application. I add the header to the request using following directive in Apache configuration file:

<VirtualHost *:443>
  ...
  RequestHeader add X-Request-Start "%t"
  CustomLog "/var/log/apache2/access.log" "%v %l %u %t \"%r\" %>s %b \"%{X-Request-Start}i\""
  ...
</VirtualHost>

The 2nd line is there to save the header value to a log file to verify, that the header is successfully added.

In my Rails application I expect to have header HTTP_X_REQUEST_START available in a hash request.env. But the header is not there! I've found that Passenger removes it from some stupid performance problems... I also found that Nginx server support directive passenger_pass_header, which forces the Passenger to keep the header in a request. Under Apache there is no similar directive. I've found keyword always, which could be added to the directive RequestHeader in Apache config. Unfortunately this directive work only with the directive Header. The directive RequestHeader doesn't know this keyword.

Does anyone know relevant way how to force Passenger to pass the header to my Rails app?

My environment: Ubuntu 18.04.2 LTS, Apache/2.4.29, Phusion Passenger 6.0.2, Rails 3.2, Ruby 1.9.3 p551.

I spend already 2 days with this problem with no success. I tried to ask for help also Chat GPT :-), but its answers were buggy. At the end I had to inform GPT about correct result! :-o

Aucun commentaire:

Enregistrer un commentaire