• Avalanche.Core
Search Results for

    Show / Hide Table of Contents
    • Avalanche.Accessor
      • Introduction
      • IAccessor
        • IAccessor
        • IListAccessor
        • IMapAccessor
        • IRecordAccessor
        • IContentAccessor
        • IOneOfAccessor
        • IAnyAccessor
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • Dependency Injection
        • AccessorMessages
    • Avalanche.Binding
      • Introduction
    • Avalanche.Core
      • License
    • Avalanche.DataType
      • Introduction
      • DataType
        • IDataType
        • IListType
        • IMapType
        • IRecordType
        • IFieldType
        • IOneOfType
        • IAnyType
        • IStringType
        • IValueType
        • IIntegerType
        • IEnumerationType
        • IRealType
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • Enum
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • DataTypeRequest
        • PrintTree
        • DataTypeMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • Avalanche.FileSystem
      • Introduction
      • Abstractions
        • IFileSystem
          • IFileSystemBrowse
          • IFileSystemCreateDirectory
          • IFileSystemDelete
          • IFileSystemFileAttribute
          • IFileSystemMount
          • IFileSystemMove
          • IFileSystemObserve
          • IFileSystemOpen
        • IEvent
        • IEntry
        • IOption
        • IToken
      • FileSystem
      • VirtualFileSystem
      • MemoryFileSystem
      • EmbeddedFileSystem
      • HttpFileSystem
      • Decoration
      • IFileProvider
      • Events
      • Utilities
        • Dispose
        • File Scanner
        • Visit Tree
        • File Operation
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
      • Asp.Net
        • Introduction
        • Supplying localization
        • Inject to pages
        • Culture Assigned
        • Minimalistic Api
        • Diagnostics
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR40
        • Unicode.CLDR41
        • Unicode.CLDR42
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
        • Printing templates
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Microsoft.Extensions
        • DependencyInjection
      • Articles
        • Aggregate Messages
        • Localization
        • Logging
        • Validation
    • Avalanche.Service
      • Introduction
      • Service
        • Introduction
        • IService
        • IServiceDisposable
        • IServiceDecoration
        • IServiceCast
        • IServiceObservable
        • IServiceContainer
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Scope
      • Handler
        • Introduction
        • IHandler
        • IHandlerCast
        • IHandlerDecoration
        • IHandlerWithOrder
        • CancellationToken
        • Cyclicity
        • Delegates
        • Invokable
        • ExportAttribute
        • OrderAttribute
        • PrintTree
        • Recursion
      • Query
        • Introduction
        • IQuery
        • IQueryCast
        • IQueryDecoration
      • Entry
        • Introduction
        • IEntry
        • IEntryCast
        • IEntryDecoration
        • IEntryObservable
        • IEntryVisitable
        • EntryState
      • Request
        • Introduction
        • IRequest
        • IRequestFor
        • IRequestToBeCached
        • IRequestToBeDisposed
        • RequestAttribute
        • ContextParameterAttribute
        • Print Tree
      • Dependency Injection
        • Introduction
        • Asp.Net
        • ServiceRequest<T>
        • Decorating a service
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • ItfMessages
        • Win32Messages
        • ClrMessages
      • System
        • Introduction
        • AccessControlMessages
        • AggregateMessages
        • AppDomainMessages
        • ArgumentMessages
        • ArgumentNullMessages
        • ArgumentOutOfRangeMessages
        • ArithmeticMessages
        • ArrayMessages
        • AssemblyMessages
        • BadImageFormatMessages
        • CodeContractMessages
        • CodePageMessages
        • CollectionsMessages
        • CompilerServiceMessages
        • CryptographyMessages
        • CultureMessages
        • DiagnosticsMessages
        • EventSourceMessages
        • ExecutionEngineMessages
        • FormatMessages
        • HostProtectionMessages
        • IOMessages
        • IndexOutOfRangeMessages
        • InteropServiceMessages
        • InvalidCastMessages
        • InvalidOperationMessages
        • IsolatedStorageMessages
        • LazyMessages
        • MarshalerMessages
        • MemoryMessages
        • MiscellaneousMessages
        • NotImplementedMessages
        • NotSupportedMessages
        • ObjectDisposedMessages
        • OperationCanceledMessages
        • OverflowMessages
        • PlatformMessages
        • PolicyMessages
        • PrincipalMessages
        • ProgramMessages
        • ReferenceMessages
        • ReflectionMessages
        • RegionMessages
        • RemotingMessages
        • ResourcesMessages
        • SecurityMessages
        • SerializationMessages
        • StackMessages
        • TaskMessages
        • TextMessages
        • ThreadingMessages
        • TimeZoneMessages
        • TypeMessages
        • XmlMessages
      • HttpStatusCode
      • OpcUaStatusCode
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Utilities
      • Introduction
      • Collections
        • Tuples
        • StructList
        • ArrayList
        • BijectionMap
        • LocakableDictionary
        • LockableList
        • MapList
        • Pipe
        • RingQueue
        • EnumerableExtensions
        • TupleUtilities
        • ArrayUtilities
      • Comparers
        • IGraphComparer
        • IGraphComparable
        • AlphaNumericComparer
        • EnumerableComparer
        • EnumerableGraphComparer
        • ReferenceComparer
        • KeyValuePairComparer
        • DefaultComparerProvider
        • RecordComparer
      • Cloners
        • ICloner
        • IGraphCloner
        • IGraphCloneable
        • ListCloner
        • DictionaryCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Pipe
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
        • IProviderEvent
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • String
        • IEscaper
        • UnicodeString
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • Void
    • Avalanche.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    Introduction

    Avalanche.StatusCode.Http.dll contains Http StatusCodes, [git], [www].

    Add package reference to .csproj.

    <PropertyGroup>
        <RestoreAdditionalProjectSources>https://avalanche.fi/Avalanche.Core/nupkg/index.json</RestoreAdditionalProjectSources>
    </PropertyGroup>
    <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.
    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

    Links

    • https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes
    • https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=net-7.0
    • https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
    In This Article
    Back to top Copyright © Toni Kalajainen