示例#1
0
        public MultipartReader(string boundary, Stream stream, int bufferSize)
        {
            if (bufferSize < boundary.Length + 8) // Size of the boundary + leading and trailing CRLF + leading and trailing '--' markers.
            {
                throw new ArgumentOutOfRangeException("bufferSize", bufferSize, "Insufficient buffer space, the buffer must be larger than the boundary: " + boundary);
            }
            _stream   = new BufferedReadStream(stream, bufferSize);
            _boundary = boundary;
            // This stream will drain any preamble data and remove the first boundary marker.
            _currentStream = new MultipartReaderStream(_stream, _boundary, expectLeadingCrlf: false);


            HeaderLengthLimit    = 1024 * 4;
            TotalHeaderSizeLimit = 1024 * 16;
        }
示例#2
0
        public async Task <MultipartSection> ReadNextSectionAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            // Drain the prior section.
            await _currentStream.DrainAsync(cancellationToken);

            // If we're at the end return null
            if (_currentStream.FinalBoundaryFound)
            {
                // There may be trailer data after the last boundary.
                await _stream.DrainAsync(cancellationToken);

                return(null);
            }
            var headers = await ReadHeadersAsync(cancellationToken);

            _currentStream = new MultipartReaderStream(_stream, _boundary);
            long?baseStreamOffset = _stream.CanSeek ? (long?)_stream.Position : null;

            return(new MultipartSection()
            {
                Headers = headers, Body = _currentStream, BaseStreamOffset = baseStreamOffset
            });
        }