Exemplo n.º 1
0
        public void OnRequest(HttpRequestHead request, IDataProducer body, IHttpResponseDelegate response)
        {
            _log.DebugFormat("Start Processing request for : {0}:{1}", request.Method, request.Uri);
            if (GetHandlerCount() < 1)
            {
                ReturnHttpMockNotFound(response);
                return;
            }

            var handler = _requestMatcher.Match(request, _handlers);

            if (handler == null)
            {
                _log.DebugFormat("No Handlers matched");
                ReturnHttpMockNotFound(response);
                return;
            }
            HandleRequest(request, body, response, handler);
        }
Exemplo n.º 2
0
        public void OnRequest(HttpRequestHead request, IDataProducer body, IHttpResponseDelegate response)
        {
            _log.DebugFormat("Start Processing request for : {0}:{1}", request.Method, request.Uri);
            if (GetHandlerCount() < 1)
            {
                ReturnHttpMockNotFound(response);
                return;
            }
            IRequestHandler handler          = null;
            Guid            currentRequestId = Guid.Empty;

            if (request.Headers == null)
            {
                _log.DebugFormat("No header specified");
            }
            else if (request.Headers.ContainsKey(Constants.MockSessionHeaderKey))
            {
                currentRequestId = new Guid(request.Headers[Constants.MockSessionHeaderKey]);
            }
            else if (request.Headers.ContainsKey(Constants.CookieHeaderKey) && request.Headers[Constants.CookieHeaderKey].Contains("="))
            {
                var mockSessionId = request.Headers[Constants.CookieHeaderKey].Split("=".ToCharArray());
                currentRequestId = new Guid(mockSessionId[1]);
            }
            RequestHandlerList requestHandler;

            if (_handlers.TryGetValue(currentRequestId, out requestHandler))
            {
                lock (requestHandler)
                {
                    handler = _requestMatcher.Match(request, requestHandler);
                }
            }
            if (handler == null)
            {
                _log.DebugFormat("No Handlers matched");
                ReturnHttpMockNotFound(response);
                return;
            }
            HandleRequest(request, body, response, handler);
        }