Page 1 of 1

How to add custom http headers

Posted: Thu Aug 03, 2023 3:00 am
by jasanchez
Hi,

It may have already been asked, but I just can't find it.
How do I add custom http headers, like x-date?

Thanks.

Javier Sanchez

Re: How to add custom http headers

Posted: Thu Aug 03, 2023 12:33 pm
by jonboy49
You use the http_xproc API with the first parameter of HTTP_POINT_ADDL_HEADER to specify your custom routine to be called and then build the required header content in that procedure.

Here's how I use it with Zoom APIs - this call has to occur before you invoke the http_string or whatever of the http APIs you are using to invoke the web service.

Code: Select all

   // Notify httpapi of the routine to use to add headers
   http_xproc( HTTP_POINT_ADDL_HEADER
             : %paddr(addSpecialHeaders)
             : %addr(authorizationToken) );
The actual addSpecialHeaders() routine looks like this:

Code: Select all

// AddSpecialHeaders
//   Called by httpapi to add the headers
//   In this case the header is just the authentication token (the JWT)

Dcl-Proc addSpecialHeaders;
   Dcl-Pi *N;
      headersToAdd    Varchar(32767);
      var             like(authorizationToken) const;
   End-Pi;

   Dcl-c  CRLF  x'0d25';

   headersToAdd = 'authorization: ' + var + CRLF;

End-Proc;

Re: How to add custom http headers

Posted: Fri Aug 04, 2023 12:25 am
by jasanchez
Excelent!
Thank you!!!!!