/// <summary> /// Destroys the internal variables used to read the message /// </summary> private void CleanupVars() { // reset our internal vars _chunk = null; _chunkedBody = null; _parser = null; _receivedBytes = null; _headerOffsetStart = -1; _headerOffsetEnd = -1; }
/// <summary> /// Initializes internal variables used to read the message /// </summary> private void InitVars() { // reset our internal vars _state = Processing.FirstLine; _chunk = null; _chunkedBody = null; _parser = new HttpByteParser(); _receivedBytes = null; _headerOffsetStart = -1; _headerOffsetEnd = -1; }
/// <summary> /// Tries to parse some chunk data for the message /// </summary> /// <returns></returns> private bool TryAndParseChunkData(ref HttpMessage message, HttpMessageProgressEventHandler 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); }
/// <summary> /// Tries to parse some chunk data for the message /// </summary> /// <returns></returns> private bool TryAndParseChunkData(ref HttpMessage message, HttpMessageProgressEventHandler 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; }