Reading custom headers from REFER message

Hello, i have a Asterisk 16.12 installed on Centos 7 with PJSIP, connected to IBM Gateway, and i have a question:

how can i read custom headers from REFER message response from another SIP Server?

1-Asterisk dial a SIP URI to IBM Gateway
2-IBM Gateway add custom sip header
3-IBM Gateway send SIP REFER message to Asterisk

The transfer is OK, but the call back does not have the custom header

I can’t see anything in RFC 3515 suggesting the UAS should do anything at all with custom headers on the REFER.

SIP_HEADERS
header function reads headers from the INVITE request, any other header you need outside the INVITE method, you will need to extract it from the logs

yes, but i have custom headers in REFER message. Not INVITE. that is my problem

Thinking outside the (Asterisk) box…

How about if you write a daemon that reads all REFER and BYE messages promiscuously off the wire.

If it’s a REFER, write all the headers of interest into a database including the call ID, header name, and header value.

If it’s a BYE, delete all rows matching the call ID. Maybe add a delete for rows older than x seconds.

Then, in your dialplan you just read the rows as you need them.