From 6444f3e15d0f8992e3fe0642a1c728ae4d49a9f0 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 27 Jan 2015 12:22:25 -0800 Subject: [PATCH] Move the reason phrase lookup to WebUtilities. --- .../ReasonPhraseHelper.cs | 66 ------------------- .../StatusCodePagesOptions.cs | 3 +- src/Microsoft.AspNet.Diagnostics/project.json | 1 + 3 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 src/Microsoft.AspNet.Diagnostics/ReasonPhraseHelper.cs diff --git a/src/Microsoft.AspNet.Diagnostics/ReasonPhraseHelper.cs b/src/Microsoft.AspNet.Diagnostics/ReasonPhraseHelper.cs deleted file mode 100644 index 9dcb5e363b..0000000000 --- a/src/Microsoft.AspNet.Diagnostics/ReasonPhraseHelper.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace Microsoft.AspNet.Diagnostics -{ - // TODO: Move this into Abstractions - public static class ReasonPhraseHelper - { - private static IDictionary Phrases = new Dictionary() - { - { 200, "OK" }, - { 201, "Created" }, - { 202, "Accepted" }, - { 203, "Non-Authoritative Information" }, - { 204, "No Content" }, - { 205, "Reset Content" }, - { 206, "Partial Content" }, - - { 300, "Multiple Choices" }, - { 301, "Moved Permanently" }, - { 302, "Found" }, - { 303, "See Other" }, - { 304, "Not Modified" }, - { 305, "Use Proxy" }, - { 306, "Switch Proxy" }, - { 307, "Temporary Redirect" }, - - { 400, "Bad Request" }, - { 401, "Unauthorized" }, - { 402, "Payment Required" }, - { 403, "Forbidden" }, - { 404, "Not Found" }, - { 405, "Method Not Allowed" }, - { 406, "Not Acceptable" }, - { 407, "Proxy Authentication Required" }, - { 408, "Request Timeout" }, - { 409, "Conflict" }, - { 410, "Gone" }, - { 411, "Length Required" }, - { 412, "Precondition Failed" }, - { 413, "Request Entity Too Large" }, - { 414, "Request-URI Too Long" }, - { 415, "Unsupported Media Type" }, - { 416, "Requested Range Not Satisfiable" }, - { 417, "Expectation Failed" }, - { 418, "I'm a teapot" }, - { 419, "Authentication Timeout" }, - - { 500, "Internal Server Error" }, - { 501, "Not Implemented" }, - { 502, "Bad Gateway" }, - { 503, "Service Unavailable" }, - { 504, "Gateway Timeout" }, - { 505, "HTTP Version Not Supported" }, - { 506, "Variant Also Negotiates" }, - }; - - public static string GetReasonPhrase(int statusCode) - { - string phrase; - return Phrases.TryGetValue(statusCode, out phrase) ? phrase : string.Empty; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/StatusCodePagesOptions.cs b/src/Microsoft.AspNet.Diagnostics/StatusCodePagesOptions.cs index 8b440a242d..6a3ee7de16 100644 --- a/src/Microsoft.AspNet.Diagnostics/StatusCodePagesOptions.cs +++ b/src/Microsoft.AspNet.Diagnostics/StatusCodePagesOptions.cs @@ -5,6 +5,7 @@ using System; using System.Globalization; using System.Threading.Tasks; using Microsoft.AspNet.Http; +using Microsoft.AspNet.WebUtilities; namespace Microsoft.AspNet.Diagnostics { @@ -18,7 +19,7 @@ namespace Microsoft.AspNet.Diagnostics // Note the 500 spaces are to work around an IE 'feature' var statusCode = context.HttpContext.Response.StatusCode; var body = string.Format(CultureInfo.InvariantCulture, "Status Code: {0}; {1}", - statusCode, ReasonPhraseHelper.GetReasonPhrase(statusCode)) + new string(' ', 500); + statusCode, ReasonPhrases.GetReasonPhrase(statusCode)) + new string(' ', 500); return context.HttpContext.Response.SendAsync(body, "text/plain"); }; } diff --git a/src/Microsoft.AspNet.Diagnostics/project.json b/src/Microsoft.AspNet.Diagnostics/project.json index d180b2787a..cee4486e1e 100644 --- a/src/Microsoft.AspNet.Diagnostics/project.json +++ b/src/Microsoft.AspNet.Diagnostics/project.json @@ -3,6 +3,7 @@ "description": "ASP.NET 5 Middleware for error handling, error pages, and diagnostics information.", "dependencies": { "Microsoft.AspNet.RequestContainer": "1.0.0-*", + "Microsoft.AspNet.WebUtilities": "1.0.0-*", "Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" } }, "frameworks": {