From 679813e4f9e0d59dd175805f52a5c43ba06ef220 Mon Sep 17 00:00:00 2001 From: rg2011 <52279456+rg2011@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:09:00 +0200 Subject: [PATCH] fix literals --- lib/services/stats/statsRegistry.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/services/stats/statsRegistry.js b/lib/services/stats/statsRegistry.js index 791551275..1ce1fdd7b 100644 --- a/lib/services/stats/statsRegistry.js +++ b/lib/services/stats/statsRegistry.js @@ -79,6 +79,9 @@ function globalLoad(values, callback) { */ function matchContentType(accepts) { const requestedType = []; + const vlabel = 'version='; + const clabel = 'charset='; + const qlabel = 'q='; for (const expression of accepts.split(',')) { const parts = expression.split(';').map((part) => part.trim()); const mediaType = parts[0]; @@ -86,25 +89,25 @@ function matchContentType(accepts) { let charset = null; let preference = null; for (let part of parts.slice(1)) { - if (part.startsWith('version=')) { - version = part.substring(8).trim(); - } else if (part.startsWith('charset=')) { - charset = part.substring(8).trim(); - } else if (part.startsWith('q=')) { - preference = parseFloat(part.substring(2).trim()); + if (part.startsWith(vlabel)) { + version = part.substring(vlabel.length).trim(); + } else if (part.startsWith(clabel)) { + charset = part.substring(clabel.length).trim(); + } else if (part.startsWith(qlabel)) { + preference = parseFloat(part.substring(qlabel.length).trim()); } } requestedType.push({ mediaType: mediaType, version: version, charset: charset, - preference: preference || 1 + preference: preference || 1.0 }); } // If both text/plain and openmetrics are accepted, // prefer openmetrics const mediaTypePref = { - 'application/openmetrics-text': 1, + 'application/openmetrics-text': 1.0, 'text/plain': 0.5 } // sort requests by priority descending