Exemple #1
0
 public string ToHttp()
 {
     return(HttpVersionUtils.ConvertToString(Version)
            + " "
            + HttpStatusCodeUtils.ConvertToNumberString(StatusCode)
            + " "
            + HttpStatusCodeUtils.ConvertToFormattedString(StatusCode)
            + "\r\n"
            + Message.ToHttp());
 }
Exemple #2
0
        public static HttpResponseValidationCode Validate(string response, out HttpVersion version, out HttpStatusCode status)
        {
            var elements = response?.Split(' ') ?? new string[0];

            if (elements.Length > 0)
            {
                version = HttpVersionUtils.Parse(elements[0]);
                if (version == HttpVersion.Unknown)
                {
                    status = HttpStatusCode.Unkown;
                    return(HttpResponseValidationCode.UnknownVersion);
                }
            }
            else
            {
                version = HttpVersion.Unknown;
                status  = HttpStatusCode.Unkown;
                return(HttpResponseValidationCode.NoVersion);
            }

            if (elements.Length > 1)
            {
                var stat_int_success = int.TryParse(elements[1], out int stat_int);
                if (!stat_int_success)
                {
                    status = HttpStatusCode.Unkown;
                    return(HttpResponseValidationCode.StatusNotInt);
                }

                var stat_sucecss = HttpStatusCodeUtils.ConvertFromNumber(stat_int, out status);
                if (!stat_sucecss)
                {
                    return(HttpResponseValidationCode.UnknownStatus);
                }
            }
            else
            {
                status = HttpStatusCode.Unkown;
                return(HttpResponseValidationCode.NoStatus);
            }

            return(HttpResponseValidationCode.Valid);
        }