Search code examples
asterisk

PJSIP How to forward all the SIP headers as received in incoming call


I am running an Asterisk 20.03 SIP server. I receive multiple X Headers in the incoming SIP INVITE, and I want to send all these SIP headers when I forward this INVITE to the connected SIP client.

I did try below configuration:

; extensions.conf

[default]
exten => 1234,1,Set(X-My-ID = ${PJSIP_HEADER(read,X-My-ID)})
exten => 1234,1,Set(X-My-Loc = ${PJSIP_HEADER(read,X-My-Loc)})
exten => 1234,1,Set(X-My-Add = ${PJSIP_HEADER(read,X-My-Add)})
exten => 1234,1,Dial(PJSIP/1234,10)

But I don't see the SIP headers getting added in the INVITE to SIP client.

I want to forward all these SIP headers received in the INVITE, how can I do that?


Solution

  • You're just setting the value of a variable with these lines:

    exten => 1234,1,Set(X-My-ID = ${PJSIP_HEADER(read,X-My-ID)})
    exten => 1234,1,Set(X-My-Loc = ${PJSIP_HEADER(read,X-My-Loc)})
    exten => 1234,1,Set(X-My-Add = ${PJSIP_HEADER(read,X-My-Add)})
    

    You're also not incrementing the priority so none of those lines will get executed anyway.

    I think this should do what you're looking for:

    [headers]
    exten => add,1,Set(PJSIP_HEADER(add,X-My-ID)=${MyID})
     same => n,Set(PJSIP_HEADER(add,X-My-Loc)=${MyLoc})
     same => n,Set(PJSIP_HEADER(add,X-My-Add)=${MyAdd})
    
    [default]
    exten => 1234,1,Set(_MyID=${PJSIP_HEADER(read,X-My-ID)})
     same => n,Set(_MyLoc=${PJSIP_HEADER(read,X-My-Loc)})
     same => n,Set(_MyAdd=${PJSIP_HEADER(read,X-My-Add)})
     same => n,Dial(PJSIP/${EXTEN},10,b(headers^add^1))
    

    This sets the value of channel variables with the header values, and then the Dial command calls another context to add these values in to the headers. See a similar question on Server Fault for more details.