Beispiel #1
0
        private static async Task <bool?> ParseHeaderLineAsync(StreamReader reader,
                                                               Action <string, string> onHeaderLine)
        {
            var line = await reader.ReadLineAsync();

            if (line.Length == 0)
            {
                return(null);
            }

            return(RawParser.ParseHeaderLine(line, onHeaderLine));
        }
Beispiel #2
0
        public static bool ParseMessage(Stream stream,
                                        Action <string, string, string> onHeadingLine,
                                        Action <string, string> onHeaderLine)
        {
            // why Debug.Assert? in production code there's no excuse to pass null delegates
            Debug.Assert(onHeadingLine != null);
            Debug.Assert(onHeaderLine != null);

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

            var reader = new StreamReader(stream);

            var headingParsing = RawParser.ParseHeadingLine(reader.ReadLine(), onHeadingLine);

            if (!headingParsing)
            {
                return(false);
            }

            while (true)
            {
                var headerLine = reader.ReadLine();
                headerLine = headerLine ?? string.Empty;
                if (headerLine.Length == 0)
                {
                    break;
                }
                var headerParsing = RawParser.ParseHeaderLine(headerLine, onHeaderLine);
                if (!headerParsing)
                {
                    return(false);
                }
            }

            return(true);
        }