예제 #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
        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
        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
        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;
        }