OverSIP
OverSIP copied to clipboard
Error when trying to change sip destination domain prior proxying
Hi guys,
I found an issue with sip destination domain change in "To" request attribute.
The use case in which I found the bug is:
def (OverSIP::SipEvents).on_request request
# the whole file is from the sample
...
case request.sip_method
when :INVITE, :MESSAGE, :OPTIONS, :SUBSCRIBE, :PUBLISH, :REFER
if MyExampleApp.do_user_assertion
::OverSIP::Modules::UserAssertion.add_pai request
end
request.to.host = 'my.custom_gateway.com'
request.ruri.host = 'my.custom_gateway.com'
proxy = ::OverSIP::SIP::Proxy.new
proxy.on_provisional_response do |response|
log_info "on_provisional_response: #{response.status_code} '#{response.reason_phrase}'"
end
proxy.on_success_response do |response|
log_info "on_success_response: #{response.status_code} '#{response.reason_phrase}'"
end
proxy.on_failure_response do |response|
log_info "on_failure_response: #{response.status_code} '#{response.reason_phrase}'"
end
proxy.on_error do |status, reason|
log_notice "on_error: #{status} '#{reason}'"
end
proxy.on_invite_timeout do
log_notice "INVITE timeout, no final response before Timer C expires."
end
log_info "doing route request"
log_info "request ruri: #{request.ruri}"
# if accessing request.to.to_s, request.to_s wont change "To" variable due to to_was_modified going false after to.to_s
log_info "debug_to: #{request.to}."
log_info "debug_to(2): #{request.to}."
# log_info "new request to: #{request.to}. Modified: #{request.to.modified?}"
# log_info request.to_s
proxy.route request, 'my.custom_gateway.com', 5060, :tcp
return
Resuming:
If we access request.to.to_s before proxying, the request.to.host is gone
Should I create a pull request for this? I would comment the to_was_modified in request.to_s so it allways change 'To' header
Sorry for the delay. Good catch. Anyhow I don't want to remove the "to_was_modified" check as it is there for performance. Let me think about it.