PJSIP_RESPONSE_HEADER(action,name[,number])
PJSIP_RESPONSE_HEADER allows you to read specific SIPSession Initiation Protocol, the standard signaling protocol used to set up, manage, and tear down VoIP calls between Asterisk and phones or carriers. headers of 200 response from the outbound PJSIP channel.
Examples:
exten => 1,1,Set(somevar=${PJSIP_RESPONSE_HEADER(read,From)})
exten => 1,1,Set(via2=${PJSIP_RESPONSE_HEADER(read,Via,2)})
exten => 1,1,Set(xhdr=${PJSIP_RESPONSE_HEADER(read,X-*,1)})
Note
If you call PJSIP_RESPONSE_HEADER in a normal dialplanThe core call-routing configuration of Asterisk, written mostly in extensions.conf as contexts, extensions, and priorities that decide how every call is handled. Full definition → contextA named section of the dialplan that groups extensions. Calls enter a specific context and can only reach extensions visible from it, making contexts the basic unit of call routing and security. you'll be operating on the caller's (incoming) channel which may not be what you want. To operate on the callee's (outgoing) channel call PJSIP_RESPONSE_HEADER in a pre-connect handler.
[handler]
exten => readheader,1,NoOp(PJSIP_RESPONSE_HEADER(read,X-MyHeader))
[somecontext]
exten => 1,1,Dial(PJSIP/${EXTEN},,U(handler^readheader^1))
actionrequiredread- Returns instance number of response header name.
namerequired - The name of the response header. A*can be appended to the name to iterate over all response headers beginning with name.number- If there's more than 1 header with the same name, this specifies which header to read. If not specified, defaults to1meaning the first matching header.
User Notes
Know a tip or gotcha for this topic? Share it below and help others.
Contribute a note
Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.