Question
David Underhill · Jan 14, 2020

%CSP.Rest custom headers

I would like a REST client to be able to send a custom header with the http request, for example "APPLICATION-ID".

This can be seen in the CSP gateway trace but I have tried using %request.GetCgiEnv("HTTP_APPLICATION-ID") in various formats and parts of the classes but cannot work out where I can get this.  Documentation says this should work but is for normal CSP pages.

Any ideas?

 

00
1 0 6 126

Replies

To determine contents of %request, %response and %session objects you can add this to the beginning of your code

set %response.ContentType = "html"
do ##class(%CSP.Utils).DisplayAllObjects()
quit $$$OK

It would return detailed information about the request as an html page.

That was very helpfull as it shows the value is not available, it does not appear in the list of CGI variables.

However, both the clients log and the CSP Gateway trace show the request had this in

Client record from SoapUI

CSP trace

CGI Variables from the details provided by the suggested output is attached as a PDF <update> attaching is failing unfortunately.

I am obviously doing something wrong so any pointers would be helpfull

This is one of the things I have tried but it is always undefined wherever I place this code.

Combined with the other answer this is working now, seems you MUST prefix a custom header value with an X.

Ok this was actually very helpful in conjunction with the previous debug advice as adding X to create x-application-id now sees the value as available and I can retrieve it as expected.

Thank you both for the help.

I think it is:

write %request.GetCgiEnv("HTTP_APPLICATION_ID")

Although by convention, custom headers should begin with a X character to avoid possible conflicts with future but spec-based implementations.