/// <summary> /// Tries to parse a trailer header for the message /// </summary> /// <returns></returns> private bool TryAndParseTrailerHeaderLine(ref HttpMessage message, HttpMessageProgressEventHandler onProgress, object stateObject) { // try and parse a token from the data HttpByteParserToken token = _parser.GetNextToken(); if (token == null) { // change state to processing the body _state = Processing.Finished; // we're done with the headers return(true); } // the first line of any message is never empty if (token.IsEmpty) { // change state to processing the body _state = Processing.Finished; // we're done with the headers return(true); } // success! this line is a header string line = token.ToString(HttpUtils.Encoding); // parse the line into a new header HttpHeader header = HttpHeader.Parse(line); // save the header in the chunked body trailers _chunkedBody.TrailerHeaders.Add(header); return(true); }
/// <summary> /// Tries to parse a chunk size line for the message /// </summary> /// <returns></returns> private bool TryAndParseChunkSizeLine(ref HttpMessage message, HttpMessageProgressEventHandler onProgress, object stateObject) { // try and parse a token from the data HttpByteParserToken token = _parser.GetNextToken(); if (token == null) { return(false); } // the first line of any message is never empty if (token.IsEmpty) { return(false); } // success! this line is a header string line = token.ToString(HttpUtils.Encoding); // parse the size line HttpChunkSizeLine chunkSizeLine = HttpChunkSizeLine.Parse(line); // create a new chunk _chunk = new HttpChunk(chunkSizeLine, null); // change state to processing chunk data _state = Processing.ChunkData; return(true); }
/// <summary> /// Tries to parse the first line for the message /// </summary> /// <returns></returns> private bool TryAndParseFirstLine(ref HttpMessage message, HttpMessageProgressEventHandler onProgress, object stateObject) { // try and parse a token from the data HttpByteParserToken token = _parser.GetNextToken(); if (token == null) { return(false); } // the first line of any message is never empty if (token.IsEmpty) { return(false); } // success! store the first line of the message message._firstLine = token.ToString(HttpUtils.Encoding); // save the offset into the data where the headers start _headerOffsetStart = _parser.Index; // change state to processing headers! _state = Processing.HeaderLine; return(true); }
/// <summary> /// Tries to parse a header line for the message /// </summary> /// <returns></returns> private bool TryAndParseHeaderLine(ref HttpMessage message, HttpMessageProgressEventHandler onProgress, object stateObject) { // try and parse a token from the data HttpByteParserToken token = _parser.GetNextToken(); if (token == null) { return(false); } // the first line of any message is never empty if (token.IsEmpty) { // save the offset into the data where the headers end _headerOffsetEnd = _parser.Index; // determine if the body is chunked, as we have all the headers now we can determine how the message is going to come in if (message.IsChunked) { // change state to processing a chunk size line _state = Processing.ChunkSizeLine; } else { // change state to processing the body _state = Processing.Body; } // notify the callback that we have received the headers this.OnProgress(onProgress, this, new HttpMessageProgressEventArgs(message, true, new byte[] {}, _receivedBytes.Length, stateObject)); // we're done with the headers return(true); } // success! this line is a header string line = token.ToString(HttpUtils.Encoding); // parse the line into a new header HttpHeader header = HttpHeader.Parse(line); // save the header message.Headers.Add(header); return(true); }