From 34bb99259716d6383fc5c51e384b935cfd2cbb96 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Fri, 1 Apr 2022 14:35:58 -0400 Subject: [PATCH] rest outdial: handle 302 redirect so we can later cancel request if needed (#95) --- lib/http-routes/api/create-call.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/http-routes/api/create-call.js b/lib/http-routes/api/create-call.js index 8300c3ee..a30ed5ac 100644 --- a/lib/http-routes/api/create-call.js +++ b/lib/http-routes/api/create-call.js @@ -132,8 +132,14 @@ router.post('/', async(req, res) => { try { const dlg = await srf.createUAC(uri, {...opts, followRedirects: true, keepUriOnRedirect: true}, { cbRequest: (err, inviteReq) => { - /* in case of 302 redirect, this gets called twice, ignore the second */ - if (res.headersSent) return; + /* in case of 302 redirect, this gets called twice, ignore the second + except to update the req so that it can later be canceled if need be + */ + if (res.headersSent) { + logger.info(`create-call: got redirect, updating request to new call-id ${req.get('Call-ID')}`); + if (cs) cs.req = inviteReq; + return; + } if (err) { logger.error(err, 'createCall Error creating call');