Class OverSIP::SIP::Request
An instance of the OverSIP::SIP::Request
class contains a parsed SIP request.
Parent class
OverSIP::SIP::Request
inherits all the methods of OverSIP::SIP::Message
.
Included modules
The following modules add methods into the OverSIP::SIP::Request
class:
Class instance methods
ruri
Gets the Request-URI parsed as a OverSIP::SIP::Uri
instance.
NOTE: If the fields of the OverSIP::SIP::Uri
instance are modified then the Request-URI will be rewritten when the request is forwarded and OverSIP will check the new Request-URI for retrieving the destination of the request (unless there is a top Route header or an explicit destination is given to the route()
method of the OverSIP::SIP::Proxy
instance).
Example
request.ruri.user
#=> "bob"
initial?
Returns true
if the request has no To ;tag
parameter.
in_dialog?
Returns true
if the request has To ;tag
parameter.
secure?
Returns true
if the request’s transport
is :tls
or :wss
.
outgoing_outbound_requested?
Returns true
if the request asks for Outbound assistance (or fix_nat()
method has been previously called).
incoming_outbound_requested?
Returns true
if the request destination is an Outbound connection established by another client.
reply
(status_code, reason_phrase=nil, extra_headers=[], body=nil)
Generate a SIP response for this SIP request which is sent stateful if a server transaction exists for this request or stateless otherwise.
Parameters
status_code
- The response status code (
Fixnum
). reason_phrase
- The reason phrase (
String
) for the response (by default the standard reason phrase for the given status code). extra_headers
- An
Array
of extra headers (Strings
) to append to the response. body
- The body (
String
) for the response.
Examples
request.reply 404
request.reply 501, "Method #{request.sip_method} not implemented"
request.reply 403, "Not Allowed", ["Content-Type: text/plain", "X-Reason: foo"], "Sorry, request not allowed"
tvars
Transaction variables. A Hash
for storing custom key / values associated to the client transaction initiated by OverSIP if this request is forwarded. The same Hash
can be later retrieved from the SIP responses replied by peers for this request via the same instance method tvars
of the OverSIP::SIP::Response
class.
Example
request.tvars[:time] = Time.now
proxy = ::OverSIP::SIP::Proxy.new
proxy.on_success_response do |response|
log_info "2XX response for a request sent at #{response.tvars[:time]}"
end
proxy.route request
cvars
Connection variables. A Hash
for storing custom key / values associated to the connection (OverSIP::SIP::Connection
or OverSIP::WebSocket::Connection
) from which the request has been received.
Example
request.cvars[:trusted_ip] = true