From 822f0da2ebbee684d148cd58bc1902a858e19c11 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 10 Nov 2022 11:10:31 +0100 Subject: [PATCH] Set charset in metrics content type (#15) Send `Content-Type: text/plain; charset=utf-8; version=0.0.4` instead of `Content-Type: text/plain; version=0.0.4` so that special characters in names have a chance to work. --- src/prometheus.ts | 2 +- tests/adapters/http/fastify.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prometheus.ts b/src/prometheus.ts index db02661..3941dc8 100644 --- a/src/prometheus.ts +++ b/src/prometheus.ts @@ -34,7 +34,7 @@ export class MetricsRenderer { const retryAfterWhileDiscovery = 15 const textContentType = 'text/plain; charset=utf-8' const prometheusSpecVersion = '0.0.4' -const metricsContentType = `text/plain; version=${prometheusSpecVersion}` +const metricsContentType = `${textContentType}; version=${prometheusSpecVersion}` function headers(contentType: string, headers: Record = {}): Record { return { ...headers, 'Content-Type': contentType } diff --git a/tests/adapters/http/fastify.test.ts b/tests/adapters/http/fastify.test.ts index 82c8ca4..de6007f 100644 --- a/tests/adapters/http/fastify.test.ts +++ b/tests/adapters/http/fastify.test.ts @@ -55,7 +55,7 @@ describe('Fastify HTTP adapter', () => { return request(testServer.http) .get('/metrics') .expect(200) - .expect('Content-Type', 'text/plain; version=0.0.4') + .expect('Content-Type', 'text/plain; charset=utf-8; version=0.0.4') .expect( [ '# TYPE homebridge_metric gauge',