SIP的消息体可以携带多种不同类型的信息。比如说SDP、QOS,甚至是安全信息。
Content-Disposition头域说明消息体的预期用途,它是个可选的报头。如果没有携带这个头域,那么假定消息体是会话相关的,即消息体的用途是描述媒体会话。除了会话描述之外,另一个定义功能是render,它意味着消息体应该呈现给用户,或者以其它方式显示出来。可以通过它传递小的JPEG图片文件或URI。
Content-Type头域指定消息体的格式。如果SIP消息携带消息体,那么必须有Content-Type头域。所有UA必须支持application/sdp类型的消息体。
Content-Encoding头域指定消息体的编码方式。如果没有指定这个头域,那么消息体就是纯文本编码的(text/plain)。Content-Encoding的方案规范允许压缩消息体。
Content-Length头域以字节为单位描述消息体的长度。即使没有消息体,也可以携带一个值为0的Content-Length头域。因为TCP流中可以同时传输多条SIP消息,所以可以利用Content-Length计算SIP消息的结束位置并确定下一条消息的起始位置。如果没有Content-Length头域,那么UAC假定UDP数据报的结束处便是SIP消息的结尾,对于TCP,则假定消息的结束点在连接关闭处,这取决于传输协议。
如果使用多部分互联网邮件扩展(Multipart Internet Mail Extensions (MIME))编码,那么消息体可以有多个组成部分。但是需要注意的是,SIP默认使用UDP传输,所以消息长度必须小于网络路径中的MTU。代理服务器可以拒绝消息体过大的请求,这时它返回413 Request Entity Too Large应答,因为处理大消息会增加服务器的负担。
SIP携带消息体的方式和e-mail携带附件的方式相同。在一条SIP消息中可以携带多个消息体。这需要通过MIME编码实现。这时Content-Type头域值描述为multipart/mime;同时指定分隔符,解析时据此分解消息体。任何SIP请求或应答消息都可以携带MIME类型的消息体。
以下是MIME消息体实例:
INVITE sip:refertarget@carol.example.com SIP/2.0
Via: SIP/2.0/UDP referree.example.com;branch=z9hG4bKffe209934aac
To: sip:refertarget@carol.example.com
From: <sip:referree@referree.example.com>;tag=2909034023
Call-ID: 9023940-a34658d
CSeq: 9823409 INVITE Max-Forwards: 70
Contact: <sip:referree@bob.example.com>
Referred-By: sip:referror@alice.example.com
;cid=%3C20398823.2UWQFN309shb3@alice.example.com%3E
Content-Type: multipart/mixed;boundary=-*-boundary-*
Content-Length: ...
—-*-boundary-*
Content-Type: application/sdp
Content-Length: ...
v=0
o=referree 2890844526 2890844526 IN IP4 referree.example
s=Session SDP
c=IN IP4 referree.example
t=0 0
m=audio 49172 RTP/AVP 0
a=rtpmap:0 PCMU/8000
—-*-boundary-*
Content-Type: multipart/signed; protocol=”application/pkcs7-signature”;
micalg=sha1; boundary=dragons39
Content-ID: <20398823.2UWQFN309shb3@alice.example.com>
Content-Length: ...
dragon39
Content-Type: message/sipfrag
Content-Disposition: auth-id; handling=optional
From: sip:referror@alice.example.com
Date: Thu, 21 Feb 2002 13:02:03 GMT
Call-ID: 2203900ef0299349d9209f023a
Refer-To: sip:refertarget@carol.example.com
Referred-By: sip:referror@alice.example.com
;cid=%3C20398823.2UWQFN309shb3@alice.example.com%3E
dragon39
Content-Type: application/pkcs7-signature; name=smime.p7s
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7s
;handling=required
(S/MIME data goes here)
—-*-boundary-*—
在消息体组成部分之间有一个字符串,本例中是-*-boundary-*-,它就是Content-Type头域中定义的分隔符。