CodeIgniter Forums
Apache Headers on Incoming Request - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Apache Headers on Incoming Request (/showthread.php?tid=78257)



Apache Headers on Incoming Request - Derek - 12-23-2020

I deal mostly in building API's and lately my authentication has been coming through as a Bearer Token passed in through an "Authorization" header. The problem that I have is that the IncomingRequest class currently does not load that header because it is not part of the $_SERVER array. In my Google searching I found that most people are suggesting to use apache_request_headers() to get that and I have created a way to do that in my code but I think this could be a valuable feature to add for anyone using CodeIgniter. My thought process is to add a configuration somewhere that allows a dev to tell CodeIgniter to check for apache headers when running the Message::populateHeaders method. Then if that is set, use apache_request_headers() to get those headers and add them to the headers in the request. What are your thoughts on that plan and where would you think makes sense to put that configuration?


RE: Apache Headers on Incoming Request - Derek - 04-29-2021

So I actually discovered that CodeIgniter has something in place in the .htaccess to make sure that the authorization header does get passed through but for some reason in my setup that wasn't working. I did find a solution that allows me to not have to use the apache_request_headers() function. I added

   
Code:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1


to my httpd.conf file and that solved the problem. I thought I would post that here in case anyone else runs into this issue and finds this post.


RE: Apache Headers on Incoming Request - MGatner - 05-02-2021

Thanks for the description and sharing the solution! This was over my head but hopefully helpful to anyone else who lands here. Smile