Пример #1
0
        public HttpResponseMessage CreateResponse(HttpRequestMessage request)
        {
            var httpRequestMessageWrapper = new HttpRequestMessageWrapper(request);
            var requestBehavior           = behaviors.FirstOrDefault(behavior => behavior.Process(httpRequestMessageWrapper));

            if (requestBehavior != null)
            {
                HttpResponseMessage httpResponseMessage;
                var httpContent = requestBehavior.Response as HttpContent;

                if (httpContent != null)
                {
                    var responseMessage = new HttpResponseMessage
                    {
                        Content    = httpContent,
                        StatusCode = requestBehavior.StatusCode
                    };
                    httpResponseMessage = responseMessage;
                }
                else
                {
                    httpResponseMessage = request.CreateResponse(requestBehavior.StatusCode, requestBehavior.Response);
                }

                var httpHeaders = requestBehavior.Headers;
                if (httpHeaders != null && httpHeaders.Count > 0)
                {
                    httpHeaders.ToList().ForEach(header => httpResponseMessage.Headers.Add(header.Key, header.Value));
                }

                httpResponseMessage.Headers.Location = requestBehavior.Location;
                return(httpResponseMessage);
            }
            return(request.CreateResponse(HttpStatusCode.OK));
        }
Пример #2
0
        public bool Process(HttpRequestMessageWrapper httpRequestMessageWrapper)
        {
            var pathAndQuery  = httpRequestMessageWrapper.RequestUri.PathAndQuery;
            var isUriMatch    = urlMatcher(pathAndQuery);
            var isMethodMatch = httpRequestMessageWrapper.Method.Equals(method.ToString());

            return(isUriMatch && isMethodMatch && RequestProcessor.Process(httpRequestMessageWrapper));
        }
Пример #3
0
 public bool Process(HttpRequestMessageWrapper httpRequestMessageWrapper)
 {
     Match = null;
     Match = DoProcess(httpRequestMessageWrapper);
     if (Match != null)
     {
         Matches.Add(Match);
     }
     return(Match != null);
 }
        public HttpResponseMessage CreateResponse(HttpRequestMessage request)
        {
            var httpRequestMessageWrapper = new HttpRequestMessageWrapper(request);
            var requestBehavior           = Behaviors.FirstOrDefault(behavior => behavior.Process(httpRequestMessageWrapper));

            if (requestBehavior != null)
            {
                return(requestBehavior.CreateResponseMessage(request));
            }
            return(request.CreateResponse(HttpStatusCode.NotFound));
        }
        protected override object DoProcess(HttpRequestMessageWrapper httpRequestMessageWrapper)
        {
            var actualRequest = httpRequestMessageWrapper.GetActualRequest <T>();
            var matched       = matchFunc(actualRequest);

            if (matched)
            {
                callback(actualRequest);
                return(actualRequest);
            }
            return(null);
        }
        public bool Process(HttpRequestMessageWrapper httpRequestMessageWrapper)
        {
            var actualRequest = httpRequestMessageWrapper.GetActualRequest <T>();
            var matched       = matchFunc(actualRequest);

            if (matched)
            {
                callback(actualRequest);
                return(true);
            }
            return(false);
        }
Пример #7
0
 protected override object DoProcess(HttpRequestMessageWrapper httpRequestMessageWrapper)
 {
     return(httpRequestMessageWrapper.GetActualRequest());
 }
Пример #8
0
 protected abstract object DoProcess(HttpRequestMessageWrapper httpRequestMessageWrapper);