示例#1
0
        public async Task Invoke(Env environment)
        {
            if (IsCallToHealthCheck(environment))
            {
                var responseHeaders = (IDictionary <string, string[]>)environment["owin.ResponseHeaders"];
                responseHeaders["Content-Type"] = new[] { Constants.Response.ContentType.Json + "; charset=utf-8" };

                var responseStream = (Stream)environment["owin.ResponseBody"];

                var healthCheckService = new HealthCheckService(configuration, new VersionProvider(configuration),
                                                                systemCheckerResolverFactory());
                var result = healthCheckService.CheckHealth(IsIntrusive(environment));

                using (var writeStream = new MemoryStream())
                {
                    var contentLength = new HealthResultJsonSerializer().SerializeToStream(writeStream, result);
                    responseHeaders["Content-Length"] = new[] { contentLength.ToString("D") };
                    writeStream.Position = 0;

                    await writeStream.CopyToAsync(responseStream);
                }
            }
            else
            {
                await next.Invoke(environment);
            }
        }
示例#2
0
        public async Task Invoke(Env environment)
        {
            if (IsCallToHealthCheck(environment))
            {
                var responseHeaders = (IDictionary<string, string[]>) environment["owin.ResponseHeaders"];
                responseHeaders["Content-Type"] = new[] {Constants.Response.ContentType.Json + "; charset=utf-8"};

                var responseStream = (Stream) environment["owin.ResponseBody"];

                var healthCheckService = new HealthCheckService(configuration, new VersionProvider(configuration),
                    systemCheckerResolverFactory());
                var result = healthCheckService.CheckHealth(IsIntrusive(environment));

                using (var writeStream = new MemoryStream())
                {
                    var contentLength = new HealthResultJsonSerializer().SerializeToStream(writeStream, result);
                    responseHeaders["Content-Length"] = new[] { contentLength.ToString("D") };
                    writeStream.Position = 0;

                    await writeStream.CopyToAsync(responseStream);
                }
            }
            else
                await next.Invoke(environment);
        }