<commit_before>﻿using System;
using System.Collections.Generic;
using Dolstagis.Web.Errors;

namespace Dolstagis.Web
{
    /// <summary>
    ///  Represents an HTTP status code.
    /// </summary>

    [Serializable]
    public class Status
    {
        private static IDictionary<int, Status> _statuses = new Dictionary<int, Status>();

        public int Code { get; private set; }

        public string Description { get; private set; }

        public string Message { get; set; }

        internal Status(int code, string description, string message)
        {
            this.Code = code;
            this.Description = description;
            this.Message = message;
            _statuses.Add(this.Code, this);
        }

        internal Status(int code, string description)
            : this(code, description, description)
        {
        }

        /// <summary>
        ///  Gets a string representation of this HTTP status.
        /// </summary>
        /// <returns>
        ///  The string representation of this status.
        /// </returns>

        public override string ToString()
        {
            return String.Format("{0} {1}", this.Code, this.Description);
        }

        /// <summary>
        ///  Gets an HTTP status object by code.
        /// </summary>
        /// <param name="code">
        ///  The HTTP status code.
        /// </param>
        /// <returns>
        ///  A <see cref="Status"/> instance, or null if undefined.
        /// </returns>

        public static Status ByCode(int code)
        {
            Status result;
            return _statuses.TryGetValue(code, out result) ? result : null;
        }

        // The values are based on the list found at http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
        // Long descriptions loosely based on those in the Apache web server

        public static readonly Status Continue = new Status(100, "Continue");
        public static readonly Status SwitchingProtocols = new Status(101, "Switching Protocols");
        public static readonly Status Processing = new Status(102, "Processing");
        public static readonly Status Checkpoint = new Status(103, "Checkpoint");

        public static readonly Status OK = new Status(200, "OK");
        public static readonly Status Created = new Status(201, "Created");
        public static readonly Status Accepted = new Status(202, "Accepted");
        public static readonly Status NonAuthoritativeInformation = new Status(203, "Non Authoritative Information");
        public static readonly Status NoContent = new Status(204, "No Content");
        public static readonly Status ResetContent = new Status(205, "Reset Content");
        public static readonly Status PartialContent = new Status(206, "Partial Content");
        public static readonly Status MultipleStatus = new Status(207, "Multiple Status");
        public static readonly Status IMUsed = new Status(226, "IM Used");

        public static readonly Status MultipleChoices = new Status(300, "Multiple Choices");
        public static readonly Status MovedPermanently = new Status
            (301, "Moved Permanently", StatusMessages.Message301MovedPermanently);
        public static readonly Status Found = new Status
            (302, "Found", StatusMessages.Message302Found);
        public static readonly Status SeeOther = new Status
            (303, "See Other", StatusMessages.Message303SeeOther);
        public static readonly Status NotModified = new Status(304, "Not Modified");
        public static readonly Status UseProxy = new Status
            (305, "Use Proxy", StatusMessages.Message305UseProxy);
        [Obsolete("This status has been removed from the HTTP/1.1 specification. See RFC2616 §10.3.7")]
        public static readonly Status SwitchProxy = new Status(306, "Switch Proxy");
        public static readonly Status TemporaryRedirect = new Status
            (307, "Temporary Redirect", StatusMessages.Message307TemporaryRedirect);
        public static readonly Status ResumeIncomplete = new Status(308, "Resume Incomplete");

        public static readonly ErrorStatus BadRequest = new ErrorStatus
            (400, "Bad Request", StatusMessages.Message400BadRequest);
        public static readonly ErrorStatus Unauthorized = new ErrorStatus
            (401, "Unauthorized", StatusMessages.Message401Unauthorized);
        public static readonly ErrorStatus PaymentRequired = new ErrorStatus
            (402, "Payment Required");
        public static readonly ErrorStatus Forbidden = new ErrorStatus
            (403, "Forbidden", StatusMessages.Message403Forbidden);
        public static readonly ErrorStatus NotFound = new ErrorStatus<commit_msg>Add a flag to statuses to indicate whether they should send a body.<commit_after>﻿using System;
using System.Collections.Generic;
using Dolstagis.Web.Errors;

namespace Dolstagis.Web
{
    /// <summary>
    ///  Represents an HTTP status code.
    /// </summary>

    [Serializable]
    public class Status
    {
        private static IDictionary<int, Status> _statuses = new Dictionary<int, Status>();

        public int Code { get; private set; }

        public string Description { get; private set; }

        public string Message { get; private set; }

        public bool HasBody { get; private set; }

        internal Status(int code, string description, string message = null, bool? hasBody = null)
        {
            this.Code = code;
            this.Description = description;
            this.Message = message ?? description;
            this.HasBody = hasBody ?? (code >= 200);
            _statuses.Add(this.Code, this);
        }


        /// <summary>
        ///  Gets a string representation of this HTTP status.
        /// </summary>
        /// <returns>
        ///  The string representation of this status.
        /// </returns>

        public override string ToString()
        {
            return String.Format("{0} {1}", this.Code, this.Description);
        }

        /// <summary>
        ///  Gets an HTTP status object by code.
        /// </summary>
        /// <param name="code">
        ///  The HTTP status code.
        /// </param>
        /// <returns>
        ///  A <see cref="Status"/> instance, or null if undefined.
        /// </returns>

        public static Status ByCode(int code)
        {
            Status result;
            return _statuses.TryGetValue(code, out result) ? result : null;
        }

        // The values are based on the list found at http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
        // Long descriptions loosely based on those in the Apache web server

        public static readonly Status Continue = new Status(100, "Continue");
        public static readonly Status SwitchingProtocols = new Status(101, "Switching Protocols");
        public static readonly Status Processing = new Status(102, "Processing");
        public static readonly Status Checkpoint = new Status(103, "Checkpoint");

        public static readonly Status OK = new Status(200, "OK");
        public static readonly Status Created = new Status(201, "Created");
        public static readonly Status Accepted = new Status(202, "Accepted");
        public static readonly Status NonAuthoritativeInformation = new Status(203, "Non Authoritative Information");
        public static readonly Status NoContent = new Status(204, "No Content", hasBody: false);
        public static readonly Status ResetContent = new Status(205, "Reset Content", hasBody: false);
        public static readonly Status PartialContent = new Status(206, "Partial Content");
        public static readonly Status MultipleStatus = new Status(207, "Multiple Status");
        public static readonly Status IMUsed = new Status(226, "IM Used");

        public static readonly Status MultipleChoices = new Status(300, "Multiple Choices");
        public static readonly Status MovedPermanently = new Status
            (301, "Moved Permanently", StatusMessages.Message301MovedPermanently);
        public static readonly Status Found = new Status
            (302, "Found", StatusMessages.Message302Found);
        public static readonly Status SeeOther = new Status
            (303, "See Other", StatusMessages.Message303SeeOther);
        public static readonly Status NotModified = new Status(304, "Not Modified", hasBody : false);
        public static readonly Status UseProxy = new Status
            (305, "Use Proxy", StatusMessages.Message305UseProxy);
        [Obsolete("This status has been removed from the HTTP/1.1 specification. See RFC2616 §10.3.7")]
        public static readonly Status SwitchProxy = new Status(306, "Switch Proxy");
        public static readonly Status TemporaryRedirect = new Status
            (307, "Temporary Redirect", StatusMessages.Message307TemporaryRedirect);
        public static readonly Status ResumeIncomplete = new Status(308, "Resume Incomplete");

        public static readonly ErrorStatus BadRequest = new ErrorStatus
            (400, "Bad Request", StatusMessages.Message400BadRequest);
        public static readonly ErrorStatus Unauthorized = new ErrorStatus
            (401, "Unauthorized", StatusMessages.Message401Unauthorized);
        public static readonly ErrorStatus PaymentRequired = new ErrorStatus
            (402, "Payment Required");
        public static readonly ErrorStatus Forbidden = new ErrorStatus
            (403, "Forbidden", StatusMessages.Message403Forbidden);
        public static readonly ErrorStatus NotFound = new ErrorStatus
{'fraction_non_alphanumeric': 0.08944954128440367, 'fraction_numerical': 0.02408256880733945, 'mean_word_length': 2.587509349289454, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4909822', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2232, 'n_words': 857}