Brian Palmund · Aug 9, 2016

How to get custom HTTP request headers

I cant find any description on how to read custom http request headers in a REST service.

On some occations i want to read http headers passed along when customers uses our REST API or headers added by the CND provider. Does anyone know how to read these http headers?

For example: sends a vistors country information along to the server using a customer http header called "CF-IPCountry". We would like to read this information and use it for statistics.

0 1,568
Discussion (3)0
Log in or sign up to continue

You can do it as in any CSP page/class. With %request, which is object of class %CSP.Request

And headers available in property CgiEnvs, where every http header appear with a prefix HTTP_

So, you may try this code.

set ipCountry=%request.GetCgiEnv("HTTP_CF-IPCOUNTRY")

Perfect! It works like a charm....

The documentation on CGI Environment Variables only refers to a set of variables to available. I does not describe that all http headers is readable thru HTTP_<header>.



One little detail. Any dash (-) is converted to underscore (_) so the correct code in this example is:

set ipCountry=%request.GetCgiEnv("HTTP_CF_IPCOUNTRY")

for a header called CF-IPCOUNTRY.