Supported 头修改
PID 开启

背景
最近需要和某家厂商的录音服务器对接,需要添加一些X-header进行参数传递。
需求
添加一些X-header到SIP,顺便也写一下如何删除。
SIP的X-header可用于在SIP中传递非标准的信息。
添加
application=”set” data=”sip_h_X-next-top=10.0.1.202:9080”/>
去除
application=”unset” data=”sip_h_X-next-top”/>
———————————————————————————————
FreeSWITCH修改头 指定代理添 加请求头 响应头 自定义头等
**
Specifying SIP Proxy With fs_path
You can route a call through a specific SIP proxy by using the “fs_path” directive. Example:
sofia/foo/user@that.domain;fs_path=sip:proxy.this.domain
Channel Variables
Adding Request Headers
You can add arbitrary headers to outbound SIP calls by prefixing the string ‘siph‘ to any channel variable, for example:
Note that for BYE requests, you will need to use the prefix ‘sipbye_h‘ on the channel variable.
Informational Tip
While not required, you should prefix your headers with “X-“ to avoid issues with interoperability with other SIP stacks.
All inbound SIP calls will install any X- headers into local variables.
This means you can easily bridge any X- header from one FreeSWITCH instance to another.
To access the header above on a 2nd box, use the channel variable ${siph_X-Answer}
It is important to note that the syntax ${sip_h_customer-header} can’t be used to retrieve any custom header not starting with X-.
It is because Sofia only reads and puts into variables custom headers starting with X-.
Adding Response Headers
There are three types of response header prefixes that can be set:
Response header
sip_rh
Provisional response header
sipph
Bye response header
sipbye_h
Each prefix will exclusively add headers for their given types of requests - there is no “global” response header prefix that will add a header to all response messages.
For example:
Adding Custom Headers
For instance, you may need P-Charge-Info to append to your INVITE header, you may do as follows:
![CDATA[sip_h_P-Charge-Info=<sip:${caller_id_number}@${domain_name};npi=0;noa=3]]>
Then, you would see it in SIP message:
INVITE sip:19099099099@1.2.3.4 SIP/2.0
Via: SIP/2.0/UDP 5.6.7.8:5080;rport;branch=z9hG4bKyg61X9v3gUD4g
Max-Forwards: 69
From: “DJB” sip:2132132132@5.6.7.8;tag=XQKQ322vQF5gK
To: sip:19099099099@1.2.3.4
Call-ID: b6c776f6-47ed-1230-0085-000f1f659e58
CSeq: 30776798 INVITE
Contact: sip:mod_sofia@5.6.7.8:5080
User-Agent: FreeSWITCH-mod_sofia/1.2.0-rc2+git~20120713T162602Z~0afd7318bd+unclean~20120713T184029Z
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, UPDATE, INFO, REGISTER, REFER, NOTIFY
Supported: timer, precondition, path, replaces
Allow-Events: talk, hold, conference, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 229
P-Charge-Info: sip:2132132132@5.6.7.8;npi=0;noa=3
X-FS-Support: update_display,send_info.
Remote-Party-ID: “DJB” sip:2132132132@5.6.7.8;party=calling;screen=yes;privacy=off
Strip SIP Headers
Strip SIP Headers
Additional Channel variables
Additional variables may also be set to influence the way calls are handled by sofia.
For example, contacts can be filtered by setting the ‘sip_exclude_contact’ variable. Example:
Or you can perform SIP Digest authorization on outgoing calls by setting sip_auth_username and sip_auth_password variables to avoid using Gateways to authenticate. Example:
Changing the SIP Contact user FreeSWITCH normally uses mod_sofia@ip:port for the internal SIP contact. To change this to foo@ip:port, there is a variable, sip_contact_user:
{sip_contact_user=foo}sofia/my_profile/1234@192.168.0.1;transport=tcp