Update HttpStatusCode enum with updates
Latest Proposal
We should update current HttpStatusCode to include more official status codes defined in recent RFCs.
Proposed API
public enum HttpStatusCode
{
// Informational 1xx
Continue = 100,
SwitchingProtocols = 101,
+ Processing = 102,
+ EarlyHints = 103,
// Successful 2xx
OK = 200,
Created = 201,
Accepted = 202,
NonAuthoritativeInformation = 203,
NoContent = 204,
ResetContent = 205,
PartialContent = 206,
+ MultiStatus = 207,
+ AlreadyReported = 208,
+ IMUsed = 226,
// Redirection 3xx
MultipleChoices = 300,
Ambiguous = 300,
MovedPermanently = 301,
Moved = 301,
Found = 302,
Redirect = 302,
SeeOther = 303,
RedirectMethod = 303,
NotModified = 304,
UseProxy = 305,
Unused = 306,
TemporaryRedirect = 307,
RedirectKeepVerb = 307,
+ PermanentRedirect = 308,
// Client Error 4xx
BadRequest = 400,
Unauthorized = 401,
PaymentRequired = 402,
Forbidden = 403,
NotFound = 404,
MethodNotAllowed = 405,
NotAcceptable = 406,
ProxyAuthenticationRequired = 407,
RequestTimeout = 408,
Conflict = 409,
Gone = 410,
LengthRequired = 411,
PreconditionFailed = 412,
RequestEntityTooLarge = 413,
RequestUriTooLong = 414,
UnsupportedMediaType = 415,
RequestedRangeNotSatisfiable = 416,
ExpectationFailed = 417,
+ // Removed status code: ImATeapot = 418,
+ MisdirectedRequest = 421,
+ UnprocessableEntity = 422,
+ Locked = 423,
+ FailedDependency = 424,
UpgradeRequired = 426,
+ PreconditionRequired = 428,
+ TooManyRequests = 429,
+ RequestHeaderFieldsTooLarge = 431,
+ UnavailableForLegalReasons = 451,
// Server Error 5xx
InternalServerError = 500,
NotImplemented = 501,
BadGateway = 502,
ServiceUnavailable = 503,
GatewayTimeout = 504,
HttpVersionNotSupported = 505,
+ VariantAlsoNegotiates = 506,
+ InsufficientStorage = 507,
+ LoopDetected = 508,
+ NotExtended = 510,
+ NetworkAuthenticationRequired = 511,
}
Details
Values added from WinRT: Windows.Web.Http.HttpStatusCode:
AlreadyReported
FailedDependency
IMUsed
InsufficientStorage
Locked
LoopDetected
MultiStatus
NetworkAuthenticationRequired
None (not sure what's this, not added)
NotExtended
PermanentRedirect
PreconditionRequired
Processing
RequestHeaderFieldsTooLarge
TooManyRequests
UnprocessableEntity
VariantAlsoNegotiates
- RFC 2324:
ImATeapot - RFC 7540:
MisdirectedRequest - RFC 7725:
UnavailableForLegalReasons - RFC 8297:
EarlyHints
Original Proposal
Please update with codes from RFCs 2817, 5785, 6266, 6585.
Main RFC, with links to update RFCs: https://tools.ietf.org/html/rfc2616
RFC2616 is obsolete now. The latest set of HTTP RFCs are 7230 thru 7240:
http://tools.ietf.org/html/rfc7230
Also, are you asking for adding new enum values or changing existing ones? We can't change existing ones. And adding new ones would be an API change which we would have to figure out how to get working across all the platforms as well as Desktop.
cc: @SidharthNabar
New ones:
207: https://tools.ietf.org/html/rfc4918#section-11.1
422: https://tools.ietf.org/html/rfc4918#section-11.2 423: https://tools.ietf.org/html/rfc4918#section-11.3 424: https://tools.ietf.org/html/rfc4918#section-11.4
428: https://tools.ietf.org/html/rfc6585#section-3 429: https://tools.ietf.org/html/rfc6585#section-4 431: https://tools.ietf.org/html/rfc6585#section-5
507: https://tools.ietf.org/html/rfc4918#section-11.5
511: https://tools.ietf.org/html/rfc6585#section-6
If we make a new enum or type we should also look at the fact that we have our own
https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.Http.Abstractions/StatusCodes.cs#L6
/cc @Tratcher @Eilon
Don't understand why you would have another enum type that is substantially similar to System.Net HttpStatusCode.
cc: @ericstj @weshaggard
What @davidsh said. But if we must have a new one, perhaps it should be more complete?
I'm fuzzy on the reasons but it might have been a dependency thing? Where are the status codes defined right now? It might have also been a flexibility thing so it was ok to change outside of .NET Framework (since we didn't want to bother unifying the type).
https://msdn.microsoft.com/en-us/library/system.net.httpstatuscode(v=vs.110).aspx
We chose a different strategy for two reasons:
- We found that using an
enumto describe this was cumbersome when the API you're calling uses anintdue to the required cast. If your code is staying within theSystem.Netuniverse there's no problem, but the moment you try to interoperate with any other code you end up with casts. - We found that having the status codes in the names of the values helped usability (subjective, of course). If anyone out there is like me, I remember half the HTTP status codes by name (e.g. NoContent), and half by number (302 is temporary redirect).
We chose a different strategy for two reasons
Fine concerns, but to me neither of those seems like enough reason to introduce another type with the same values for the same purpose. (And for the second case, if the first is an enum, then you can do (HttpStatusCode)302 if you want the enum value associated with the number.) My $.02.
Can't change this type because it unifies with .NET Framework right? That's another good reason to make a new one.
I'm not following why that's a good reason. Why not just add additional values to HttpStatusCode here and then to the desktop implementation the next time it revs? We need to be able to add additional members/etc. to existing framework types, and shouldn't just add a new type every time we want to augment something. In some cases, sure, it makes sense to branch out; this doesn't seem like one of them to me, at least not for the cited reasons.
@stephentoub Because it forces multi-targeting if anyone wants to use a new enum value.
Or just using it by number until they're able to upgrade to the newer version of the contract, e.g. (HttpStatusCode)302. I'd much prefer that than having two types for the same purpose.
Or just have one type in a new place that doesn't unify because it's just a class and there's little value (IMO) in unifying this enum.
This is all getting side-tracked from the real reason we did this; we didn't want the type to be an enum because it's a poor fit for this data set, so we choose const int's instead.
Actually, it's getting side-tracked because the issue reported here is about missing status codes. :smile:
That said, I'll throw in a +1 for the enum over const int because of enum's inherent discoverability. There is already a precedent in the framework for static consts intended to help consistency (around MIME types, I think), but each time I need them, I have to hunt around for the static class that declares them. We can't have string based enums in C# but we can for ints, and it's definitely convenient.
@mteper We've been through most of this discussion (also, re: discoverability) at https://github.com/aspnet/HttpAbstractions/pull/345#issuecomment-131011572
Thanks @khellang!
Funny, I saw that thread back when it was originally discussed and completely forgot about it! FWIW, I'd back your struct-based proposal.
Back to the issue at hand, whatever mechanism the .NET folks decide to go with, can we add in the extra codes now, which the bits are still baking?