You could use some Kemi/Javascript function to do the conversion, though, I
don't think you will benefit much from doing that conversion and back....
here is a Kemi JS function that converts SIP headers to JSON structure. It
is called using app_jsdt module.
Modify it at will to do whatever you want .
// converts SIP headers to JSON object, supporting repeated headers
(converts to Array of strings)
// and also support any custom SIP headers
function headers_to_json() {
try {
var raw = KSR.pv.get("$mb") || "";
var headers = {};
var displayKeyFor = {}; // canonicalLower -> chosen display name
(preserves first-seen casing)
// Split full SIP message into lines and isolate the header section
var lines = raw.split(/\r\n|\n/);
var startLine = (lines.length > 0) ? lines[0] : "";
var i = 1; // start after Request/Status line
var headerLines = [];
var current = null;
// Reconstruct logical header lines (handle obsolete line folding:
lines starting with SP/HTAB)
for (; i < lines.length; i++) {
var line = lines[i];
// End of header section (blank line before message body)
if (line === "") {
break;
}
if (line.length > 0 && (line.charAt(0) === ' ' ||
line.charAt(0) === '\t')) {
// Continuation of previous header
if (current !== null) {
// Trim leading whitespace on the continuation and join
with a single space
current += " " + line.replace(/^\s+/, "");
}
} else {
// New header starts
if (current !== null) headerLines.push(current);
current = line;
}
}
if (current !== null) headerLines.push(current);
// RFC 3261 compact form expansions (common ones)
var compactMap = {
"i": "Call-ID",
"m": "Contact",
"e": "Content-Encoding",
"l": "Content-Length",
"c": "Content-Type",
"f": "From",
"s": "Subject",
"t": "To",
"v": "Via",
"k": "Supported"
};
function titleCaseHeader(name) {
var parts = name.split("-");
for (var j = 0; j < parts.length; j++) {
var p = parts[j];
if (p.length > 0) {
parts[j] = p.charAt(0).toUpperCase() +
p.slice(1).toLowerCase();
}
}
return parts.join("-");
}
function canonicalName(name) {
var n = (name || "").trim();
var low = n.toLowerCase();
if (compactMap.hasOwnProperty(low)) return compactMap[low];
// For all other headers (standard or custom), create a nice
Title-Case key
return titleCaseHeader(n);
}
// Build JSON object: single occurrence -> string; multiple
occurrences -> array of strings
for (var h = 0; h < headerLines.length; h++) {
var l = headerLines[h];
var idx = l.indexOf(":");
if (idx < 0)
continue; // skip malformed lines (shouldn't happen in
valid SIP)
var nameRaw = l.substring(0, idx);
var value = l.substring(idx + 1).replace(/^\s+/, ""); // trim
leading spaces after colon
var name = nameRaw; //canonicalName(nameRaw);
var keyLower = name.toLowerCase();
var outKey = displayKeyFor[keyLower] || name;
if (headers.hasOwnProperty(outKey)) {
// Already seen: ensure it is an array and append
if (Object.prototype.toString.call(headers[outKey]) ===
"[object Array]") {
headers[outKey].push(value);
} else {
headers[outKey] = [headers[outKey], value];
}
} else {
headers[outKey] = value; // first occurrence
-> string
displayKeyFor[keyLower] = outKey; // remember chosen
display name
}
}
// Convenience fields (optional)
var method = KSR.pv.get("$rm");
if (method)
headers.Method = method;
var ruri = KSR.pv.get("$ru");
if (ruri)
headers["Request-URI"] = ruri;
var json_str = JSON.stringify(headers);
KSR.pv.sets("$var(headers_json)", json_str);
return 1;
} catch (e) {
KSR.log("error", "Failed to convert headers to JSON: " +
e.toString() + "\n");
return -1;
}
}
Atenciosamente / Kind Regards / Cordialement / Un saludo,
*Sérgio Charrua*
*www.kahea.ai <http://www.kahea.ai> / www.voip.pt <http://www.voip.pt>*
*OpenTelecom* - Consulting for Telecoms, Lda
Tel.: +351 <callto:+351+91+104+12+66>91 631 11 44
Email : *[email protected] <[email protected]>*
This message and any files or documents attached are strictly confidential
or otherwise legally protected.
It is intended only for the individual or entity named. If you are not the
named addressee or have received this email in error, please inform the
sender immediately, delete it from your system and do not copy or disclose
it or its contents or use it for any purpose. Please also note that
transmission cannot be guaranteed to be secure or error-free.
On Thu, Feb 5, 2026 at 10:08 AM 13715209697--- via sr-users <
[email protected]> wrote:
> Hi, Alex Balashov
>
> You are right; I made a mistake.
>
> Configure the following parameter under the FreeSWITCH SIP Profile:
>
> <param name="enable-compact-headers" value="true"/>
>
> I hope Kamailio can expand compact-headers into normal SIP headers.
> Currently, it seems Kamailio can only relay them as-is.
> __________________________________________________________
> Kamailio - Users Mailing List - Non Commercial Discussions --
> [email protected]
> To unsubscribe send an email to [email protected]
> Important: keep the mailing list in the recipients, do not reply only to
> the sender!
>
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions --
[email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the
sender!