Skip to content

Commit 801107a

Browse files
committed
Kestrel refactor
1 parent f9bd768 commit 801107a

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/Prometheus.Client.MetricServer/MetricServer.Kestrel.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,20 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
226226

227227
public void Configure(IApplicationBuilder app)
228228
{
229-
app.Run(context =>
229+
app.Map(_mapPath, coreapp =>
230230
{
231-
if (context.Request.Path == _mapPath)
231+
coreapp.Run(async context =>
232232
{
233233
var response = context.Response;
234-
response.ContentType = Defaults.ContentType;
234+
response.ContentType = Defaults.ContentType;
235235

236236
using (var outputStream = response.Body)
237237
{
238238
ScrapeHandler.Process(_registry, outputStream);
239239
}
240240

241-
return Task.FromResult(true);
242-
}
243-
244-
context.Response.StatusCode = 404;
245-
return Task.FromResult(true);
241+
await Task.FromResult(0).ConfigureAwait(false);
242+
});
246243
});
247244
}
248245
}

tests/Prometheus.Client.MetricServer.NetCore.Tests/MetricServerTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ public async Task Base_MapPath()
3636
}
3737

3838
[Fact]
39-
public async Task MapPath_WithEndSlash_NotWorking()
39+
public async Task MapPath_WithEndSlash()
4040
{
4141
const int port = 9000;
4242
var metricServer = new MetricServer(port, "/test");
4343
metricServer.Start();
4444

4545
using (var httpClient = new HttpClient())
4646
{
47-
await Assert.ThrowsAsync<HttpRequestException>(() => httpClient.GetStringAsync($"http://localhost:{port}/test/"));
47+
var response = await httpClient.GetStringAsync($"http://localhost:{port}/test/");
48+
Assert.False(string.IsNullOrEmpty(response));
4849
}
4950

5051
metricServer.Stop();

0 commit comments

Comments
 (0)