#174 - Constants for status codes, lookup for reason phrases.

This commit is contained in:
Chris Ross 2015-01-27 12:18:34 -08:00
parent e71c585eb3
commit 096a0bf298
2 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,65 @@
// 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.WebUtilities
{
public static class ReasonPhrases
{
private static IDictionary<int, string> Phrases = new Dictionary<int, string>()
{
{ 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;
}
}
}

View File

@ -0,0 +1,54 @@
// 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.
namespace Microsoft.AspNet.WebUtilities
{
public static class StatusCodes
{
public const int Status200OK = 200;
public const int Status201Created = 201;
public const int Status202Accepted = 202;
public const int Status203NonAuthoritative = 203;
public const int Status204NoContent = 204;
public const int Status205ResetContent = 205;
public const int Status206PartialContent = 206;
public const int Status300MultipleChoices = 300;
public const int Status301MovedPermanently = 301;
public const int Status302Found = 302;
public const int Status303SeeOther = 303;
public const int Status304NotModified = 304;
public const int Status305UseProxy = 305;
public const int Status306SwitchProxy = 306;
public const int Status307TemporaryRedirect = 307;
public const int Status400BadRequest = 400;
public const int Status401Unauthorized = 401;
public const int Status402PaymentRequired = 402;
public const int Status403Forbidden = 403;
public const int Status404NotFound = 404;
public const int Status405MethodNotAllowed = 405;
public const int Status406NotAcceptable = 406;
public const int Status407ProxyAuthenticationRequired = 407;
public const int Status408RequestTimeout = 408;
public const int Status409Conflict = 409;
public const int Status410Gone = 410;
public const int Status411LengthRequired = 411;
public const int Status412PreconditionFailed = 412;
public const int Status413RequestEntityTooLarge = 413;
public const int Status414RequestUriTooLong = 414;
public const int Status415UnsupportedMediaType = 415;
public const int Status416RequestedRangeNotSatisfiable = 416;
public const int Status417ExpectationFailed = 417;
public const int Status418ImATeapot = 418;
public const int Status419AuthenticationTimeout = 419;
public const int Status500InternalServerError = 500;
public const int Status501NotImplemented = 501;
public const int Status502BadGateway = 502;
public const int Status503ServiceUnavailable = 503;
public const int Status504GatewayTimeout = 504;
public const int Status505HttpVersionNotsupported = 505;
public const int Status506VariantAlsoNegotiates = 506;
}
}