Exemple #1
0
        public static HeaderSection CreateNew(string headersString)
        {
            headersString = HeaderField.CorrectObsFolding(headersString);

            var hs = new HeaderSection();

            if (headersString.EndsWith(CRLF + CRLF))
            {
                headersString = headersString.TrimEnd(CRLF, StringComparison.Ordinal);
            }

            using (var reader = new StringReader(headersString))
            {
                while (true)
                {
                    var field = reader.ReadLine(strictCRLF: true);
                    if (field is null)
                    {
                        break;
                    }
                    hs.Fields.Add(HeaderField.CreateNew(field));
                }

                ValidateAndCorrectHeaders(hs);

                return(hs);
            }
        }
        public static async Task <HeaderSection> CreateNewAsync(string headersString)
        {
            headersString = HeaderField.CorrectObsFolding(headersString);

            var hs = new HeaderSection();

            if (headersString.EndsWith(CRLF + CRLF))
            {
                headersString = headersString.TrimEnd(CRLF, StringComparison.Ordinal);
            }

            using var reader = new StringReader(headersString);
            while (true)
            {
                var field = reader.ReadLine(strictCRLF: true);
                if (field is null)
                {
                    break;
                }
                hs.Fields.Add(await HeaderField.CreateNewAsync(field).ConfigureAwait(false));
            }

            ValidateAndCorrectHeaders(hs);

            return(hs);
        }