Esempio n. 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();
            }
        }