private static RequestHandling FormatRequest(HttpRequestMessage request)
        {
            RequestHandling handling = new RequestHandling();

            if (!request.RequestUri.IsAbsoluteUri)
            {
                request.RequestUri = new Uri("http://example.com/" + request.RequestUri.OriginalString);
            }
            var requestString = request.ToString();

            handling.Request = requestString.Replace("\r\n{\r\n}", "{}");
            return(handling);
        }
        private static HttpControllerDescriptor GetHttpControllerDescriptor(HttpRequestMessage request, HttpConfiguration config, RequestHandling handling, IHttpRouteData routeData)
        {
            if (handling.Handler != null)
            {
                return(null);
            }

            RemoveOptionalRoutingParameters(routeData.Values);
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
            try
            {
                return(new DefaultHttpControllerSelector(config).SelectController(request));
            }
            catch (HttpResponseException ex)
            {
                handling.Handler = string.Format("{0}: {1}", (int)ex.Response.StatusCode, ex.Response.ReasonPhrase);
                return(null);
            }
        }
        private static void FindRouting(HttpRequestMessage request, HttpConfiguration config, RequestHandling handling)
        {
            var routeData = config.Routes.GetRouteData(request);

            if (routeData == null)
            {
                handling.Handler = "No route found";
            }
            var httpControllerDescriptor = GetHttpControllerDescriptor(request, config, handling, routeData);

            if (handling.Handler == null)
            {
                handling.Handler = GetHandlerText(request, config, routeData, httpControllerDescriptor);
            }
        }