Skip to content

Commit

Permalink
fix literals
Browse files Browse the repository at this point in the history
  • Loading branch information
rg2011 committed Aug 9, 2024
1 parent bc6caf8 commit 679813e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/services/stats/statsRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,35 @@ 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];
let version = null;
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
Expand Down

0 comments on commit 679813e

Please sign in to comment.