URSA.Web.Http.HeaderCollection.Parse C# (CSharp) Method

Parse() public static method

Parses a given string as a HeaderCollection.
public static Parse ( string headers ) : HeaderCollection
headers string String to be parsed.
return HeaderCollection
        public static HeaderCollection Parse(string headers)
        {
            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            if (headers.Length == 0)
            {
                throw new ArgumentOutOfRangeException("headers");
            }

            HeaderCollection result = new HeaderCollection();
            var matches = Header.Matches(headers);
            foreach (Match match in matches)
            {
                result.Add(Http.Header.Parse(match.Value));
            }

            return result;
        }

Usage Example

コード例 #1
0
        /// <summary>Parses a given string as a <see cref="RequestInfo" />.</summary>
        /// <param name="method">Method of the request.</param>
        /// <param name="url">URL of the request.</param>
        /// <param name="message">Request content.</param>
        /// <returns>Instance of the <see cref="RequestInfo" />.</returns>
        public static RequestInfo Parse(Verb method, HttpUrl url, string message)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            if (!url.IsAbsolute)
            {
                throw new ArgumentOutOfRangeException("url");
            }

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (message.Length == 0)
            {
                throw new ArgumentOutOfRangeException("message");
            }

            string[]         parts    = Regex.Split(message, "\r\n\r\n");
            Encoding         encoding = Encoding.UTF8;
            HeaderCollection headers  = HeaderCollection.Parse(parts[0]);

            return(new RequestInfo(method, url, (parts.Length > 1 ? new MemoryStream(encoding.GetBytes(parts[1].Trim('\r', '\n'))) : new MemoryStream()), new BasicClaimBasedIdentity(), headers));
        }
All Usage Examples Of URSA.Web.Http.HeaderCollection::Parse