Ye Lin Kyaw Random Thoughts

PHP-FPM & HTTP Headers

Apache 2.4 is dropping the HTTP Header names with special characters for some security reasons. The header names with underscore character are also included in dropped headers. Some of my apps are suffering with this. Even for the security reason, it is needed to support the existing apps for backward compatibility. According to the Apache Document, the original header name encoding can be accepted by using mod_setenvif and mod_headers.

SetEnvIfNoCase ^Accept.Encoding\( ^(.*)\) fix_accept_encoding=$1

RequestHeader set Accept-Encoding %{fix_accept_encoding}e env=fix_accept_encoding

According to the above configuration, HTTP Headers should be readable by using apache_request_headers() with mod_php. But the problem is still existed for using PHP-FPM with FastCGI. The custom HTTP Headers are needed to pass specifically as follow.

SetEnvIf APP123_VAR1 “(.*)” APP123_VAR1=$1

SetEnvIf APP123_VAR2 “(.*)” APP123_VAR2=$1