File tree Expand file tree Collapse file tree 2 files changed +8
-21
lines changed
examples/WebApiApplication Expand file tree Collapse file tree 2 files changed +8
-21
lines changed Original file line number Diff line number Diff line change 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 ;
72using System . Web . Http ;
83using Prometheus . Client ;
94using 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 }
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments