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.
This commit is contained in:
Lars Strojny 2022-11-10 11:10:31 +01:00 committed by GitHub
parent f6bc8ca90c
commit 822f0da2eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -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<string, string> = {}): Record<string, string> {
return { ...headers, 'Content-Type': contentType }

View file

@ -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',