/// <summary>
		/// Process a received FastCGI message
		/// </summary>
		/// <param name="message"></param>
		protected virtual void ReceiveMessage(Message message)
		{
			var requestId = message.Header.RequestId;
            var requestType = message.Header.MessageType;

            _logger.Log(LogLevel.Verbose, "Received message (request {0}) {1} of length {2}", requestId, requestType, message.Body.Count);

			switch (requestType)
			{
				case MessageType.BeginRequest:
					this.BeginRequest(message);
					break;

				case MessageType.AbortRequest:
                    _requestsRepository.GetRequest(requestId).Abort();
					break;

				case MessageType.Params:
                    _requestsRepository.GetRequest(requestId).ParametersStream.Append(message.Body);
					break;

				case MessageType.StandardInput:
					if (message.Header.ContentLength > 0)
                        _requestsRepository.GetRequest(requestId).InputStream.Append(message.Body);
					else
                        _requestsRepository.GetRequest(requestId).Execute();
					break;

				case MessageType.Data:
                    _requestsRepository.GetRequest(requestId).DataStream.Append(message.Body);
					break;

				case MessageType.GetValues:
					this.SendGetValuesResult(message.Body);
					break;

				default:
					break;
			}
		}
 private Request CreateRequestInternal(Message message)
 {
     var request = this.CreateRequest(message.Header.RequestId, new BeginRequestMessageBody(message.Body));
     request.Ended += new EventHandler(OnRequestEnded);
     request.OutputFlushing += new EventHandler<FlushEventArgs>(OnRequestOutputFlushing);
     request.ErrorFlushing += new EventHandler<FlushEventArgs>(OnRequestErrorFlushing);
     return request;
 }
		/// <summary>
		/// Sends a message to the FastCGI client
		/// </summary>
		/// <param name="message"><typeparamref name="Message"/> to send</param>
		protected virtual void SendMessage(Message message)
		{
            _logger.Log(LogLevel.Verbose, "Sending message (request {0}) {1} of length {2}", message.Header.RequestId, message.Header.MessageType, message.Body.Count);
			this.LowerLayer.Send(message.ToByteArray());
		}
		/// <summary>
		/// Creates and initalize a <typeparamref name="Request"/> 
		/// </summary>
		/// <param name="message">BeginRequest message</param>
		protected virtual void BeginRequest(Message message)
		{
			if (message.Header.RecordType != RecordType.Application)
				return;

			if (message.Body.Count < Consts.ChunkSize)
				return;

            _requestsRepository.AddRequest(CreateRequestInternal(message));
		}