예제 #1
0
        private void processRequest(ReceiveHeaderCompleteEventArgs e)
        {
            logger.Debug("{0} process request", _connectionToken.Substring(0, 6));

            if (_lastProcessor != null)
            {
                _lastProcessor.Close();
            }

            HttpRequestHeader requestHeader = (HttpRequestHeader)e.LastReceiveHeader;

            logger.Debug("{0} receive new request: {1}, url: {2}",
                         _connectionToken.Substring(0, 6),
                         requestHeader.Method,
                         requestHeader.Url);

            //check if keep connection alive
            _clientKeepAlive = (requestHeader.Connection == null ||
                                String.Compare(requestHeader.Connection, "keep-alive", true) == 0);

            _lastResponseHeader        = new HttpResponseHeader();
            _lastResponseHeader.Date   = DateTime.Now.ToUniversalTime();
            _lastResponseHeader.Server = HttpServiceControler.SERVER_NAME;

            HandlerContext context = new HandlerContext(
                requestHeader, _lastResponseHeader, _bindEndPoint, _bindEndPointName, _clientIp, _connectionToken);

            _lastProcessor = _processorFactory.CreateProcessor(context);
            _lastProcessor.ProcessRequest(context);

            //request contains body
            if (requestHeader.ContentLength > 0)
            {
                if (_lastProcessor.RequestBodyAcceptable)
                {
                    //continue to receive reqeust body
                    _workStatus = SessionWorkStatus.ReceivingRequestBody;
                    e.TotalPlanReceivingLength = requestHeader.ContentLength;
                }
                else
                {
                    //NOTE::
                    //can not accept request body, because
                    //some http method (GET,HEAD,DELETE) should not contain request body
                    //or POST,PUT access deny.
                    logger.Warn("{0} processor {1} can not accept request body",
                                _connectionToken.Substring(0, 6),
                                _lastProcessor.GetType().Name);
                    Close();
                }
            }
            else
            {
                sendResponse();
            }
        }
예제 #2
0
        private void session_ReceiveBodyComplete(object sender, ReceiveBodyCompleteEventArgs e)
        {
            logger.Debug("{0} receive body complete", _connectionToken.Substring(0, 6));

            _lastActiveTime = DateTime.Now;
            _workStatus     = SessionWorkStatus.Busy;

            try
            {
                _lastProcessor.RequestBodyArrival(e.Data, e.DataLength);

                if (e.TotalHasReceivedLength >= e.TotalPlanReceivingLength)
                {
                    //all body receive complete
                    _lastProcessor.AllRequestBodyReceived();
                }
            }
            catch (Exception ex)
            {
                //exception occur while append request body to handler,
                //only PUT and POST will occur.
                logger.Warn("{0} append request to processor {1} body error: {2}",
                            _connectionToken.Substring(0, 6),
                            _lastProcessor.GetType().Name,
                            ex.Message);
                Close();
                return;
            }

            if (e.TotalHasReceivedLength >= e.TotalPlanReceivingLength)
            {
                //handle complete, send response
                sendResponse();
            }
            else
            {
                //continue to receive body
                _workStatus = SessionWorkStatus.ReceivingRequestBody;
                _session.ContinueReceivingBody(_bodyBuffer, 0, _bodyBuffer.Length);
            }
        }