예제 #1
0
        private static Response GetResponse(MetricsEndpointResponse endpointResponse)
        {
            var response = new Response();

            response.StatusCode  = (HttpStatusCode)endpointResponse.StatusCode;
            response.ContentType = endpointResponse.ContentType;
            response.Contents    = stream =>
            {
                using (var writer = new StreamWriter(stream, endpointResponse.Encoding))
                {
                    writer.Write(endpointResponse.Content);
                }
            };
            return(response.WithHeaders(noCacheHeaders));
        }
예제 #2
0
        private static async Task WriteResponse(MetricsEndpointResponse response, IDictionary <string, object> environment)
        {
            var responseStream = environment["owin.ResponseBody"] as Stream;
            var headers        = environment["owin.ResponseHeaders"] as IDictionary <string, string[]>;

            var contentBytes = response.Encoding.GetBytes(response.Content);

            headers["Content-Type"]  = new[] { response.ContentType };
            headers["Cache-Control"] = new[] { "no-cache, no-store, must-revalidate" };
            headers["Pragma"]        = new[] { "no-cache" };
            headers["Expires"]       = new[] { "0" };

            environment["owin.ResponseStatusCode"] = (int)response.StatusCode;

            await responseStream.WriteAsync(contentBytes, 0, contentBytes.Length);
        }
        public void MetricsEndpointResponse_HasSaneDefaults()
        {
            var response = new MetricsEndpointResponse("content", "content-type");

            response.Content.Should().Be("content");
            response.ContentType.Should().Be("content-type");
            response.Encoding.Should().Be(Metric.CurrentEncoding);
            response.StatusCode.Should().Be(200);
            response.StatusCodeDescription.Should().Be("OK");

            response = new MetricsEndpointResponse("content", "content-type", Encoding.ASCII);
            response.Content.Should().Be("content");
            response.ContentType.Should().Be("content-type");
            response.Encoding.Should().Be(Encoding.ASCII);
            response.StatusCode.Should().Be(200);
            response.StatusCodeDescription.Should().Be("OK");
        }