ResponseWritten() public static method

public static ResponseWritten ( ) : ResponseHandlerResult
return ResponseHandlerResult
        private static async Task <ResponseHandlerResult> WriteResponseInCacheAsync(HttpResponseBase httpResponse, CacheItem cacheItem)
        {
            await cacheItem.Response.WriteResponseAsync(httpResponse);

            httpResponse.Headers.Set("Last-Modified", cacheItem.CachedUtcTimestamp.ToHttpDate());

            return(ResponseHandlerResult.ResponseWritten());
        }
Ejemplo n.º 2
0
        public async Task <ResponseHandlerResult> HandleResponseAsync(HttpContextBase context, IResponse suggestedResponse, ICache cache, string cacheKey)
        {
            context.ThrowIfNull("context");
            suggestedResponse.ThrowIfNull("suggestedResponse");

            await new CacheResponse(suggestedResponse).WriteResponseAsync(context.Response);

            return(ResponseHandlerResult.ResponseWritten());
        }
        public async Task <ResponseHandlerResult> HandleResponseAsync(HttpContextBase context, IResponse suggestedResponse, ICache cache, string cacheKey)
        {
            context.ThrowIfNull("context");
            suggestedResponse.ThrowIfNull("suggestedResponse");

            StatusAndSubStatusCode statusCode = suggestedResponse.StatusCode;

            if (!_statusCodes.Contains(statusCode))
            {
                return(ResponseHandlerResult.ResponseNotHandled());
            }

            AcceptHeader[] acceptHeaders = AcceptHeader.ParseMany(context.Request.Headers["Accept"]).ToArray();

            if (acceptHeaders.Any() && !acceptHeaders.Any(arg => arg.MediaTypeMatches("text/html")))
            {
                return(ResponseHandlerResult.ResponseNotHandled());
            }

            const string format   = @"<!DOCTYPE html>
<html>
	<head>
		<title>{0}</title>
		<style>h1 {{ margin: 0; padding: 0; }}</style>
	</head>
	<body>
		<h1>{0}</h1>
		<hr/>
		HTTP {1}{2}
	</body>
</html>";
            Response     response = new Response(statusCode)
                                    .TextHtml()
                                    .Content(String.Format(format, statusCode.StatusDescription, statusCode.StatusCode, statusCode.SubStatusCode == 0 ? "" : "." + statusCode.SubStatusCode));

            response.CachePolicy.NoClientCaching();

            await new CacheResponse(response).WriteResponseAsync(context.Response);

            context.Response.TrySkipIisCustomErrors = true;

            return(ResponseHandlerResult.ResponseWritten());
        }
        public async Task <ResponseHandlerResult> HandleResponseAsync(HttpContextBase context, IResponse suggestedResponse, ICache cache, string cacheKey)
        {
            context.ThrowIfNull("context");
            suggestedResponse.ThrowIfNull("suggestedResponse");

            StatusAndSubStatusCode statusCode = suggestedResponse.StatusCode;

            if (!_statusCodes.Contains(statusCode))
            {
                return(ResponseHandlerResult.ResponseNotHandled());
            }

            AcceptHeader[] acceptHeaders = AcceptHeader.ParseMany(context.Request.Headers["Accept"]).ToArray();

            if (acceptHeaders.Any() && !acceptHeaders.Any(arg => arg.MediaTypeMatches("text/plain")))
            {
                return(ResponseHandlerResult.ResponseNotHandled());
            }

            string content = String.Format(
                "HTTP {0}{1} {2}",
                statusCode.StatusCode,
                statusCode.SubStatusCode == 0 ? "" : "." + statusCode.SubStatusCode.ToString(CultureInfo.InvariantCulture),
                statusCode.StatusDescription.Length > 0 ? String.Format("({0})", statusCode.StatusDescription) : "");
            Response response = new Response(statusCode)
                                .TextPlain()
                                .Content(content);

            response.CachePolicy.NoClientCaching();

            await new CacheResponse(response).WriteResponseAsync(context.Response);

            context.Response.TrySkipIisCustomErrors = true;

            return(ResponseHandlerResult.ResponseWritten());
        }
        private static async Task <ResponseHandlerResult> WriteResponseAsync(HttpResponseBase httpResponse, CacheResponse cacheResponse)
        {
            await cacheResponse.WriteResponseAsync(httpResponse);

            return(ResponseHandlerResult.ResponseWritten());
        }