Skip to content

Commit 9dfb8a7

Browse files
authored
Merge pull request #17 from BruTyler/master
Add encoding to Response
2 parents 163efca + 4b00f9d commit 9dfb8a7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Prometheus.Client.AspNetCore/PrometheusExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ public static IApplicationBuilder UsePrometheusServer(this IApplicationBuilder a
4141
if (options.UseDefaultCollectors)
4242
options.CollectorRegistryInstance.UseDefaultCollectors();
4343

44+
var contentType = "text/plain; version=0.0.4";
45+
46+
if (options.ResponseEncoding != null)
47+
contentType += $"; charset={options.ResponseEncoding.BodyName}";
48+
4449
void AddMetricsHandler(IApplicationBuilder coreapp)
4550
{
4651
coreapp.Run(async context =>
4752
{
4853
var response = context.Response;
49-
response.ContentType = "text/plain; version=0.0.4";
54+
55+
response.ContentType = contentType;
5056

5157
using var outputStream = response.Body;
5258
await ScrapeHandler.ProcessAsync(options.CollectorRegistryInstance, outputStream);

src/Prometheus.Client.AspNetCore/PrometheusOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text;
12
using Prometheus.Client.Collectors;
23

34
namespace Prometheus.Client.AspNetCore
@@ -26,5 +27,10 @@ public class PrometheusOptions
2627
/// Use default collectors
2728
/// </summary>
2829
public bool UseDefaultCollectors { get; set; } = true;
30+
31+
/// <summary>
32+
/// Charset of text response.
33+
/// </summary>
34+
public Encoding ResponseEncoding { get; set; }
2935
}
3036
}

0 commit comments

Comments
 (0)