Search code examples
coldfusion

How to create Custom CGI-scope variable in ColdFusion 2018


I inherited an application that has a custom variable in the CGI Scope:

CGI.HTTP_variablename

How are custom variables added to the CGI Scope in ColdFusion (in this case, version 2018).

This variable is internal to the organization and is used with CFLDAP for user verification, so it cannot be done a different way.

I also do not have access to the web server or the ColdFusion administrator to just check how it was done. All I have access to is the source code, and there is nothing in the source code that helps to answer this question.

The site itself is hosted in IIS, but the ColdFusion Administrator is running on TomCat.

Thank you.


Solution

  • That's not a "custom variable" per se. What you're seeing is a behavior of the CGI scope that allows you to access any HTTP request headers via the convention of

    cgi.http_<name of header>
    

    This means, for instance, you can access the host or user agent as either

    getHTTPRequestData().headers.host
    getHTTPRequestData().headers['user-agent']
    

    or

    cgi.http_host
    cgi['http_user-agent']
    

    Likewise, any custom HTTP headers sent from the client can be accessed in the same manners.

    getHTTPRequestData().headers.myCustomHeader
    cgi.http_myCustomHeader