Since this thread will probably end up in Google I''ll share my
experience. I ended up with this"
if(t_check_status("301|302"))
{
#NOTE: must assign to $du to keep R-URI intact
$var(contact) = $T_rpl($ct);
$var(contact) = $(var(contact){nameaddr.uri});
$du = $var(contact);
xlog("L_INFO", "Redirect from proxy intercepted - M=$rm
R=$ru F=$fu T=$tu IP=$avp(s:ip):$avp(s:port) ($si:$sp) ID=$ci\n");
append_branch();
route(ROUTE_RELAY);
exit;
}
where route(ROUTE_RELAY) is merely a call t_relay_to("0x01") wrapped up
in some logging. So far so good.
There was a problem when a new request target needed digest-ch'd the
caller with 407. The redirect server by default relayed not 407 but 302
reply back. I've set tm modparam failure_reply_mode to 3 - voila!
http://kamailio.org/docs/modules/3.1.x/modules/tm.html#failure_reply_mode