Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can access the headers of an incoming request in tritium?

I would like to be able to add some logic to my tritium project based on the incoming request header. Is it possible to access the header information and then perform match() with() logic?

My plan is to take an existing URL (that can be accessed via a normal GET request) and give it a second mode of functionality so that it can be turned into an AJAX API. When the JavaScript makes the API request, I could set a custom header flag so that the platform knows to interpret the request differently.

like image 343
naryasece Avatar asked Oct 21 '22 05:10

naryasece


1 Answers

You should be able to access headers in the incoming HTTP request using the global variable syntax. For example, to access the site's hostname:

$host
# => yourwebsite.com

I believe that most of the standard headers are accessible as global variables in Tritium. However, I'm not sure if all headers are accessible as global vars.

Inside your project folder, on your development machine, there should be a tmp folder that contains the HTTP request/response bundles. Each bundle should be time stamped with the request's date and time. I think if you peek inside one of these folders, you should see a bunch of files:

  • incoming_request
  • incoming_response
  • outgoing_request
  • outgoing_response

And possibly a fifth file. I can't remember if this is still the case in the current version of the platform, but there's a chance you'll find a fifth file containing the global variables that the Tritium server creates to store HTTP request header values. So you can peek inside that file (if it exists) and find out what variable name your HTTP headers are using.

Hope that helps!

like image 127
Zkoh Avatar answered Oct 25 '22 19:10

Zkoh