Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the byte string
        /// </summary>
        /// <param name="buffer"></param>
        public HttpByteParserToken(byte[] bytes)
        {
            if (bytes == null)
            {
                bytes = new byte[0];
            }

            _bytes = HttpUtils.Clone(bytes, 0, bytes.Length);
        }
Beispiel #2
0
        /// <summary>
        /// Tries to parse some chunk data for the message
        /// </summary>
        /// <returns></returns>
        private bool TryAndParseChunkData(ref HttpMessage message, EventHandler <HttpMessageProgressEventArgs> onProgress, object stateObject)
        {
            // get bytes, and update the index...
            int waitingOn = _chunk.Size;
            int received  = _receivedBytes.Length - 2 - _parser.Index;

            // if we received enough data to pull in a chunk, do that now
            if (received >= waitingOn)
            {
                // copy the end of the data out as chunk data
                byte[] data = HttpUtils.Clone(_receivedBytes, _parser.Index, _chunk.Size);

                // bump the parser past the end of the next \r\n
                _parser.Index += _chunk.Size + 2;

                // create a new chunked body
                if (_chunkedBody == null)
                {
                    _chunkedBody = new HttpChunkedBody();
                }

                // assign the data to the chunk
                _chunk.Data = data;

                // todo:

                // add the chunk to the body
                _chunkedBody.Chunks.Add(_chunk);

                // if the chunk is empty, it's the last chunk
                bool empty = _chunk.IsEmpty;

                // destroy the chunk
                _chunk = null;

                if (empty)
                {
                    // change state to processing chunk data
                    _state = Processing.ChunkTrailerHeaderLine;
                }
                else
                {
                    // go back to processing a chunk size line
                    _state = Processing.ChunkSizeLine;
                }

                return(true);
            }

            return(false);
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the HttpByteParserToken class
 /// </summary>
 /// <param name="bytes"></param>
 /// <param name="startIndex"></param>
 /// <param name="length"></param>
 public HttpByteParserToken(byte[] bytes, int startIndex, int length)
 {
     _bytes = HttpUtils.Clone(bytes, startIndex, length);
 }
Beispiel #4
0
 /// <summary>
 /// Returns a copy of the internal byte array
 /// </summary>
 /// <returns></returns>
 public byte[] ToByteArray()
 {
     return(HttpUtils.Clone(_bytes, 0, _bytes.Length));
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the HttpChunk class
 /// </summary>
 /// <param name="size"></param>
 /// <param name="extension"></param>
 /// <param name="data"></param>
 public HttpChunk(int size, string extension, byte[] data)
 {
     _sizeLine = new HttpChunkSizeLine(size, extension);
     _data     = HttpUtils.Clone(data, 0, data.Length);
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the HttpChunk class
 /// </summary>
 /// <param name="data"></param>
 public HttpChunk(byte[] data)
 {
     _sizeLine = new HttpChunkSizeLine(data.Length, null);
     _data     = HttpUtils.Clone(data, 0, data.Length);
 }