Introduction
Avalanche.StatusCode.Http.dll contains Http StatusCodes, [git], [www].
Add package reference to .csproj.
<ItemGroup>
<PackageReference Include="Avalanche.StatusCodes.Http"/>
</ItemGroup>
HttpStatusCodes.Instance contain message descriptions.
IMessage statusCode = HttpStatusCodes.Instance.OK.New();
Message descriptions throw HttpRequestException.
try
{
HttpStatusCodes.Instance.Forbidden.Throw();
}
catch (HttpRequestException e)
{
WriteLine(e); //
}
HttpStatusCodes.Instance.Codes query by code.
// Get by code
IMessageDescription notFound = HttpStatusCodes.Instance.Codes[404];
// Print template text
WriteLine(notFound.Template); // "NotFound"
WriteLine(notFound.Description); // "Indicates that the ..."
Table can be queried by key.
// Get by key
IMessageDescription messageDescription = HttpStatusCodes.Instance.Keys["Http.OK"];
// Print template text
WriteLine(messageDescription.Template); // "OK"
HttpStatusCodeId contain integer constants.
// Print code
WriteLine(HttpStatusCodeId.Conflict); // "409"
Full example
using Avalanche.Message;
using Avalanche.StatusCode;
using static System.Console;
class http_index
{
public static void Run()
{
{
// <00A>
IMessage statusCode = HttpStatusCodes.Instance.OK.New();
// </00A>
}
{
// <00B>
try
{
HttpStatusCodes.Instance.Forbidden.Throw();
}
catch (HttpRequestException e)
{
WriteLine(e); //
}
// </00B>
}
{
// <01>
// Get by code
IMessageDescription notFound = HttpStatusCodes.Instance.Codes[404];
// Print template text
WriteLine(notFound.Template); // "NotFound"
WriteLine(notFound.Description); // "Indicates that the ..."
// </01>
}
{
// <02>
// Get by key
IMessageDescription messageDescription = HttpStatusCodes.Instance.Keys["Http.OK"];
// Print template text
WriteLine(messageDescription.Template); // "OK"
// </02>
}
{
// <03>
// Print code
WriteLine(HttpStatusCodeId.Conflict); // "409"
// </03>
}
}
}
Mask
Http statuscodes use following mask semantics.
Mask | Name | Description |
---|---|---|
1xx | Informational | The request was received, continuing process |
2xx | Successful | The request was successfully received, understood, and accepted |
3xx | Redirection | Further action needs to be taken in order to complete the request |
4xx | Client Error | The request contains bad syntax or cannot be fulfilled |
5xx | Server Error | The server failed to fulfill an apparently valid request |
Table
Avalanche.StatusCodes.HttpStatusCodes contains following message descriptions:
CodeDecimal | Key | Description |
---|---|---|
100 | Http.Continue | Client should proceed to send the request body. |
101 | Http.SwitchingProtocols | The server agrees to switch protocol. |
102 | Http.Processing | Server is processing the request, but no response is available yet. |
103 | Http.EarlyHints | Response headers are returned before final HTTP message. |
200 | Http.OK | Successful response for successful request. |
201 | Http.Created | Resulted in one or more new resources being created. The resource created is identified by a Location header or by URI. |
202 | Http.Accepted | Request has been accepted for processing, but the processing has not been completed. The request may eventually be completed, but status code cannot be re-sent. |
203 | Http.NonAuthoritativeInformation | The content has been modified from the origin server's 200 response by a proxy. |
204 | Http.NoContent | There is no additional content to send. |
205 | Http.ResetContent | The server desires that the user agent resets the document view. |
206 | Http.PartialContent | The server is is transferring parts of the requested content. |
300 | Http.MultipleChoices | Resource has more than one representation. Server requests that the user agent selects preferred selection by redirecting th erequest to the provided identifiers. |
301 | Http.MovedPermanently | Resource has been assigned a new permanent URI. |
302 | Http.Found | Resource resides under a different URI. |
303 | Http.SeeOther | User agent is redirected to a different resource as indicated in the Location header field. |
304 | Http.NotModified | There is no need for the server to transfer the resource because the request. Server redirects to content of OK response. |
305 | Http.UseProxy | Deprecated |
307 | Http.TemporaryRedirect | Resource resides temporarily under a different URI, however the user agent should persist the reference of the original URI. |
308 | Http.PermanentRedirect | Resource has a new permanent URI and any future references should use one new one. |
400 | Http.BadRequest | Client error (malformed request syntax, invalid request message framing or deceptive request routing) |
401 | Http.Unauthorized | Request lacks valid authentication credentials. |
402 | Http.PaymentRequired | |
403 | Http.Forbidden | Server refuses fulfill request. Reason can be described in content. |
404 | Http.NotFound | Resource was not found. Whether it previously existed is not disclosed. |
405 | Http.MethodNotAllowed | Method is not supported on resource. An Allow header field is returned containing a list of supported methods. |
406 | Http.NotAcceptable | Resource cannot be represented according to header fields received in the request. |
407 | Http.ProxyAuthenticationRequired | Authentication is needed. |
408 | Http.RequestTimeout | Request message was not received within time. |
409 | Http.Conflict | Conflict within the state of the resource. |
410 | Http.Gone | Previously existing resource is gone. Similiar to 404, but discloses that resource existed in the past. |
411 | Http.LengthRequired | Content-Length is required. |
412 | Http.PreconditionFailed | A condition in request header evaluated to false. |
413 | Http.ContentTooLarge | The request content is larger than the server can process. |
414 | Http.URITooLong | URI is longer than the server can process. |
415 | Http.UnsupportedMediaType | Content format is not supported on the resoruce. |
416 | Http.RangeNotSatisfiable | Range header field has been rejected. |
417 | Http.ExpectationFailed | Expect header field could not be met. |
421 | Http.MisdirectedRequest | Request was directed at a server that is unable or unwilling to produce an authoritative response. |
422 | Http.UnprocessableContent | Server understands the requested content type, and the syntax is correct, but it was unable to process the contained instructions. |
423 | Http.Locked | Resource is locked. |
426 | Http.UpgradeRequired | Server requires updated protocol. Server sends an Upgrade header field. |
500 | Http.InternalServerError | Unexpected internal error. |
501 | Http.NotImplemented | The server does not support the request. |
502 | Http.BadGateway | Invalid response from an inbound server. |
503 | Http.ServiceUnavailable | Server is currently unable to handle the request. |
504 | Http.GatewayTimeout | The server, as a gateway or proxy, did not receive a timely response. |
505 | Http.HttpVersionNotSupported | The major version of HTTP that was used in the request message is not supported. |
110 | Http.ResponseIsStale | Resource in cache is stale state. Content's age exceeds maximum age. |
111 | Http.RevalidationFailed | Cache was unable to validate the response. |
112 | Http.DisconnectedOperation | Cache is disconnected |