@@ -87,7 +87,7 @@ public void Start()
8787 options . Listen ( IPAddress . Any , _options . Port , listenOptions => { listenOptions . UseHttps ( _options . Certificate ) ; } ) ;
8888 } )
8989 . UseUrls ( $ "http{ ( _options . Certificate != null ? "s" : "" ) } ://{ _options . Host } :{ _options . Port } ")
90- . ConfigureServices ( services => { services . AddSingleton < IStartup > ( new Startup ( _options . CollectorRegistryInstance , _options . MapPath ) ) ; } )
90+ . ConfigureServices ( services => { services . AddSingleton < IStartup > ( new Startup ( _options ) ) ; } )
9191 . UseSetting ( WebHostDefaults . ApplicationKey , typeof ( Startup ) . GetTypeInfo ( ) . Assembly . FullName )
9292 . Build ( ) ;
9393
@@ -106,15 +106,11 @@ public void Stop()
106106
107107 internal class Startup : IStartup
108108 {
109- private const string _contentType = "text/plain; version=0.0.4" ;
110- private readonly string _mapPath ;
109+ private readonly MetricServerOptions _options ;
111110
112- private readonly ICollectorRegistry _registry ;
113-
114- public Startup ( ICollectorRegistry registry , string mapPath )
111+ public Startup ( MetricServerOptions options )
115112 {
116- _registry = registry ;
117- _mapPath = mapPath ;
113+ _options = options ;
118114
119115 var builder = new ConfigurationBuilder ( ) ;
120116 Configuration = builder . Build ( ) ;
@@ -129,15 +125,20 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
129125
130126 public void Configure ( IApplicationBuilder app )
131127 {
132- app . Map ( _mapPath , coreapp =>
128+ var contentType = "text/plain; version=0.0.4" ;
129+
130+ if ( _options . ResponseEncoding != null )
131+ contentType += $ "; charset={ _options . ResponseEncoding . BodyName } ";
132+
133+ app . Map ( _options . MapPath , coreapp =>
133134 {
134135 coreapp . Run ( async context =>
135136 {
136137 var response = context . Response ;
137- response . ContentType = _contentType ;
138+ response . ContentType = contentType ;
138139
139140 using var outputStream = response . Body ;
140- await ScrapeHandler . ProcessAsync ( _registry , outputStream ) ;
141+ await ScrapeHandler . ProcessAsync ( _options . CollectorRegistryInstance , outputStream ) ;
141142 } ) ;
142143 } ) ;
143144 }
0 commit comments