Skip to content

Commit 574f644

Browse files
committed
#2: fix WebApi example
1 parent 4d329d5 commit 574f644

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

examples/WebApiApplication/Controllers/MetricsController.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System.IO;
2-
using System.Net;
3-
using System.Net.Http;
4-
using System.Net.Http.Headers;
5-
using System.Net.Mime;
6-
using System.Text;
1+
using System.Web;
72
using System.Web.Http;
83
using Prometheus.Client;
94
using Prometheus.Client.Collectors;
@@ -13,30 +8,22 @@ namespace WebApiApplication.Controllers
138
public class MetricsController : ApiController
149
{
1510
[HttpGet]
16-
public HttpResponseMessage Get()
11+
public IHttpActionResult Get()
1712
{
1813
var registry = CollectorRegistry.Instance;
1914
var acceptHeaders = Request.Headers.GetValues("Accept");
20-
2115
var contentType = ScrapeHandler.GetContentType(acceptHeaders);
16+
var reponse = HttpContext.Current.Response;
17+
reponse.ContentType = contentType;
18+
reponse.StatusCode = 200;
2219

23-
24-
string content;
25-
26-
using (var outputStream = new MemoryStream())
20+
using (var outputStream = reponse.OutputStream)
2721
{
2822
var collected = registry.CollectAll();
2923
ScrapeHandler.ProcessScrapeRequest(collected, contentType, outputStream);
30-
content = Encoding.ASCII.GetString(outputStream.ToArray());
3124
}
3225

33-
34-
var response = Request.CreateResponse(HttpStatusCode.OK);
35-
36-
response.Content = new StringContent(content, Encoding.UTF8, contentType);
37-
38-
39-
return response;
26+
return Ok();
4027

4128
}
4229
}

examples/WebApiApplication/WebApiApplication.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<AutoAssignPort>True</AutoAssignPort>
127127
<DevelopmentServerPort>11292</DevelopmentServerPort>
128128
<DevelopmentServerVPath>/</DevelopmentServerVPath>
129-
<IISUrl>http://localhost:11292/</IISUrl>
129+
<IISUrl>http://localhost:5000/</IISUrl>
130130
<NTLMAuthentication>False</NTLMAuthentication>
131131
<UseCustomServer>False</UseCustomServer>
132132
<CustomServerUrl>

0 commit comments

Comments
 (0)