/// <summary>
        /// Parses a string in the format 'Method SP Request-Uri SP Http-Version CRLF' into an HttpRequestLine instance
        /// </summary>
        /// <param name="value">The string to parse. May contain CRLF.</param>
        /// <returns></returns>
        public static HttpRequestLine Parse(string value)
        {
            string[] parts = value.Split(' ');

            if (parts.Length < 3)
            {
                return(null);
            }

            HttpProtocolVersion protocolVersion = HttpProtocolVersion.Parse(parts[2]);

            if (protocolVersion == null)
            {
                return(null);
            }

            return(new HttpRequestLine(parts[0], parts[1], protocolVersion));
        }
Пример #2
0
        /// <summary>
        /// Parses a string in the format 'HTTP-Version SP Status-Code SP Reason-Phrase CRLF' into an HttpStatusLine instance
        /// </summary>
        /// <example>
        /// HTTP/1.1 200 OK\r\n
        /// </example>
        /// <param name="value">The string to parse. May contain CRLF.</param>
        /// <returns></returns>
        public static HttpStatusLine Parse(string value)
        {
            //value = HttpUtils.StripCRLF(value);
            //string[] parts = value.Split(HttpControlChars.SP);

            int    firstSpace = value.IndexOf(HttpControlChars.SP, 0);
            string a          = value.Substring(0, firstSpace);
            string b          = value.Substring(++firstSpace);

            HttpProtocolVersion protocolVersion = HttpProtocolVersion.Parse(a);
            HttpStatus          status          = HttpStatus.Parse(b);

            if (status == null)
            {
                return(null);
            }

            return(new HttpStatusLine(protocolVersion, status));
        }