Forwarding SIP headers with asterisk (PJSIP)

Solution 1:

You can use _VARIABLE: https://wiki.asterisk.org/wiki/display/AST/Variable+Inheritance

[handler]
exten => addheader,1,NoOp(Value is ${somevar})
same => n,Set(PJSIP_HEADER(add,X-myheader=${somevar})
same => n,Return()

[internal]
exten => 6010,1,NoOp(Test)
same  => n,Set(_somevar=${PJSIP_HEADER(read,X-myheader)})
same  => n,NoOp(Value is ${somevar})
same => n,Dial(PJSIP/6010,,b(handler^addheader^1))
same => n,Hangup()