コード例 #1
0
        private IEnumerable <HttpRequestDataChunk> ReadChunksBuffered(HttpParserConfig config)
        {
            long length      = ContentLength;
            int  chunkNumber = 0;

            HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

            // If we are expecting 100 continue then we have to
            // send the header first otherwise this will block if we have a length
            if (Headers.HasHeader("Expect", "100-continue") && (length > 0))
            {
                chunk.ChunkNumber = chunkNumber++;

                yield return(chunk);

                chunk = new HttpRequestDataChunk(this);
            }

            chunk.ChunkNumber = chunkNumber;
            chunk.FinalChunk  = true;

            if (length > 0)
            {
                // Cast to length, really should just ignore any data set greater than a set amount
                chunk.Body = _reader.ReadBytes((int)length);
            }

            yield return(chunk);
        }
コード例 #2
0
        private IEnumerable <HttpRequestDataChunk> ReadChunksConnect(HttpParserConfig config)
        {
            int chunkNumber = 0;

            while (true)
            {
                byte[] data = _reader.ReadBytes(HttpParserConfig.DEFAULT_CHUNK_SIZE, false);

                if (data.Length == 0)
                {
                    throw new EndOfStreamException();
                }

                HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

                chunk.ChunkNumber = chunkNumber;

                if (chunkNumber < int.MaxValue)
                {
                    chunkNumber++;
                }

                // Cast to length, really should just ignore any data set greater than a set amount
                chunk.Body = data;

                yield return(chunk);
            }
        }
コード例 #3
0
        private IEnumerable <HttpRequestDataChunk> ReadChunksStreamed(HttpParserConfig config)
        {
            long length      = ContentLength;
            int  chunkSize   = config.StreamChunkSize;
            bool waitForAll  = true;
            int  chunkNumber = 0;

            if (chunkSize <= 0)
            {
                waitForAll = false;
                chunkSize  = HttpParserConfig.DEFAULT_CHUNK_SIZE;
            }

            // If we are expecting 100 continue then we have to
            // send the header first otherwise this will block if we have a length
            // Also send if length is as there will be no following data
            if ((length == 0) || Headers.HasHeader("Expect", "100-continue"))
            {
                HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

                chunk.ChunkNumber = chunkNumber++;

                yield return(chunk);
            }

            while (length > 0)
            {
                int readLength = length > chunkSize ? chunkSize : (int)length;

                byte[] data = _reader.ReadBytes(readLength, waitForAll);

                // While we are reading we wouldn't expect no data to be returned
                if (data.Length == 0)
                {
                    throw new EndOfStreamException();
                }

                length -= data.Length;

                HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

                chunk.ChunkNumber = chunkNumber++;
                chunk.FinalChunk  = length == 0;

                // Cast to length, really should just ignore any data set greater than a set amount
                chunk.Body = data;

                yield return(chunk);
            }
        }
コード例 #4
0
ファイル: HttpRequestHeader.cs プロジェクト: michyer/canape
        private IEnumerable<HttpRequestDataChunk> ReadChunksStreamed(HttpParserConfig config)
        {
            long length = ContentLength;
            int chunkSize = config.StreamChunkSize;
            bool waitForAll = true;
            int chunkNumber = 0;

            if (chunkSize <= 0)
            {
                waitForAll = false;
                chunkSize = HttpDataChunk.DEFAULT_CHUNK_SIZE;
            }

            // If we are expecting 100 continue then we have to
            // send the header first otherwise this will block if we have a length
            // Also send if length is as there will be no following data
            if ((length == 0) || Headers.HasHeader("Expect", "100-continue"))
            {
                HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

                chunk.ChunkNumber = chunkNumber++;

                yield return chunk;
            }

            while (length > 0)
            {
                int readLength = length > chunkSize ? chunkSize : (int)length;

                byte[] data = _reader.ReadBytes(readLength, waitForAll);

                // While we are reading we wouldn't expect no data to be returned
                if (data.Length == 0)
                {
                    throw new EndOfStreamException();
                }

                length -= data.Length;

                HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

                chunk.ChunkNumber = chunkNumber++;
                chunk.FinalChunk = length == 0;

                // Cast to length, really should just ignore any data set greater than a set amount
                chunk.Body = data;

                yield return chunk;
            }
        }
コード例 #5
0
ファイル: HttpRequestHeader.cs プロジェクト: michyer/canape
        private IEnumerable<HttpRequestDataChunk> ReadChunksConnect(HttpParserConfig config)
        {
            int chunkNumber = 0;

            while(true)
            {
                byte[] data = _reader.ReadBytes(HttpDataChunk.DEFAULT_CHUNK_SIZE, false);

                if (data.Length == 0)
                {
                    throw new EndOfStreamException();
                }

                HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

                chunk.ChunkNumber = chunkNumber;

                if (chunkNumber < int.MaxValue)
                {
                    chunkNumber++;
                }

                // Cast to length, really should just ignore any data set greater than a set amount
                chunk.Body = data;

                yield return chunk;
            }
        }
コード例 #6
0
ファイル: HttpRequestHeader.cs プロジェクト: michyer/canape
        private IEnumerable<HttpRequestDataChunk> ReadChunksBuffered(HttpParserConfig config)
        {
            long length = ContentLength;
            int chunkNumber = 0;

            HttpRequestDataChunk chunk = new HttpRequestDataChunk(this);

            // If we are expecting 100 continue then we have to
            // send the header first otherwise this will block if we have a length
            if (Headers.HasHeader("Expect", "100-continue") && (length > 0))
            {
                chunk.ChunkNumber = chunkNumber++;

                yield return chunk;

                chunk = new HttpRequestDataChunk(this);
            }

            chunk.ChunkNumber = chunkNumber;
            chunk.FinalChunk = true;

            if (length > 0)
            {
                // Cast to length, really should just ignore any data set greater than a set amount
                chunk.Body = _reader.ReadBytes((int)length);
            }

            yield return chunk;
        }