예제 #1
0
        /// <summary>
        /// Handle an message
        /// </summary>
        /// <param name="context">Context unique for this handler instance</param>
        /// <param name="message">Message to process</param>
        public void HandleUpstream(IPipelineHandlerContext context, IPipelineMessage message)
        {
            if (message is Closed)
            {
                _bodyBytesLeft = 0;
                _headerParser.Reset();
            }
            else if (message is Received)
            {
                var msg = (Received)message;

                // complete the body
                if (_bodyBytesLeft > 0)
                {
                    var bytesToSend = Math.Min(_bodyBytesLeft, msg.BufferReader.RemainingLength);
                    _bodyBytesLeft -= bytesToSend;
                    context.SendUpstream(message);
                    return;
                }

                _headerParser.Parse(msg.BufferReader);
                if (_headerCompleted)
                {
                    var request = (IRequest)_message;

                    var ourRequest = _message as HttpRequest;
                    if (ourRequest != null)
                    {
                        ourRequest.RemoteEndPoint = msg.RemoteEndPoint as IPEndPoint;
                    }
                    request.AddHeader("RemoteAddress", msg.RemoteEndPoint.ToString());

                    var receivedHttpRequest = new ReceivedHttpRequest(request);

                    _headerParser.Reset();
                    _headerCompleted = false;

                    context.SendUpstream(receivedHttpRequest);
                    if (msg.BufferReader.RemainingLength > 0)
                    {
                        context.SendUpstream(msg);
                    }
                }

                return;
            }

            context.SendUpstream(message);
        }
예제 #2
0
        /// <summary>
        /// Reset builder state
        /// </summary>
        public void Reset()
        {
            _bodyBytestLeft = 0;
            _headerParser.Reset();

            IMessage message;

            while (_messages.TryDequeue(out message))
            {
            }
        }