Exemplo n.º 1
0
            public int Find(byte[] boundary)
            {
                int position = StreamingMultiPartParser.findSequence(
                    buffer, Position, EndPosition,
                    boundary, 0, boundary.Length);

                return(position);
            }
Exemplo n.º 2
0
            public bool StartsWith(byte[] prefix, int position = 0)
            {
                if (position < Position || position > EndPosition - prefix.Length)
                {
                    return(false);
                }
                bool result = StreamingMultiPartParser.startsWith(
                    buffer, position, EndPosition,
                    prefix, 0, prefix.Length);

                return(result);
            }
Exemplo n.º 3
0
        private async Task parseSection()
        {
            // read headers
            NameValueCollection headers = new NameValueCollection();
            await buffer.Fill(bodyStream);

            while (!buffer.IsEmpty && !buffer.StartsWith(newLine))
            {
                string header = await parseHeader();

                string[] parts = header.Split(new char[] { ':' }, 2);
                if (parts.Length == 2)
                {
                    headers.Add(parts[0].Trim(), parts[1].Trim());
                }
            }
            if (buffer.IsEmpty)
            {
                return;
            }

            // read content
            buffer.Shift(newLine.Length);
            string subBoundary = getSubBoundary(headers);

            if (subBoundary == null)
            {
                MemoryStream content = await parseContent(boundary, newLine);

                if (SectionFound != null)
                {
                    SectionFound(this, new MultiPartSection()
                    {
                        Headers = headers, Content = content
                    });
                }
            }
            else
            {
                StreamingMultiPartParser subParser = new StreamingMultiPartParser(bodyStream, encoding, subBoundary, boundary, buffer);
                if (SectionFound != null)
                {
                    subParser.SectionFound += (o, e) => SectionFound(o, e);
                }
                await subParser.parseInternal();
            }
        }