Пример #1
0
        public void Should_indicate_not_loupe_url([Values("http://www.test.com/",
                                                          "http://www.test.com/Gibraltar",
                                                          "http://www.test.com/Gibraltar/log/things",
                                                          "http://www.test.com/gibraltar/data")] string url)
        {
            HttpRequest.Url.Returns(new Uri(url));
            var checker = new UrlCheck();

            Assert.That(checker.IsLoupeUrl(HttpContext), Is.False);
        }
Пример #2
0
        public void Should_detect_loupe_url([Values("http://www.test.com/loupe/log",
                                                    "http://www.test.com/Loupe/log",
                                                    "http://www.test.com/loupe/Log",
                                                    "http://www.test.com/Loupe/Log",
                                                    "http://www.test.com/loupe/log/")] string url)
        {
            HttpRequest.Url.Returns(new Uri(url));
            var checker = new UrlCheck();

            Assert.That(checker.IsLoupeUrl(HttpContext), Is.True);
        }
        public bool HandleRequest(HttpContextBase context)
        {
            bool handled = false;

            if (IsCrossOriginRequest(context) && _urlCheck.IsLoupeUrl(context))
            {
                try
                {
                    switch (context.Request.HttpMethod)
                    {
                    case "OPTIONS":
                        CreateOptionsResponse(context);
                        handled = true;
                        break;

                    case "POST":
                        AddHeadersToPost(context);
                        // don't flag as handled as we need the request
                        // to continue through the pipeline
                        break;

                    default:
                        MethodNotSupportedResponse(context);
                        handled = true;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    GC.KeepAlive(ex);
#if DEBUG
                    Log.Error(ex, "Loupe.Internal", "Unable to handle CORS request due to " + ex.GetType(),
                              "Exception occurred trying to handle the {0} request of a CORS request\r\n{1}", context.Request.HttpMethod, ex.Message);
#endif
                    context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    handled = true;
                }
            }

            return(handled);
        }
        public bool HandleRequest(HttpContextBase context)
        {
            try
            {
                if (_urlCheck.IsLoupeUrl(context))
                {
                    return(InputStreamInvalid(context));
                }
            }
            catch (Exception ex)
            {
                GC.KeepAlive(ex);
#if DEBUG
                Log.Write(LogMessageSeverity.Critical, Constants.LogSystem, 0, ex, LogWriteMode.Queued,
                          context.StandardXmlRequestBlock(), Constants.Category, "Unable to process message due to " + ex.GetType(),
                          "Exception caught in top level catch block, this should have be caught by error handler specific to the part of the request processing that failed.");
#endif
            }

            return(false);
        }
Пример #5
0
        /// <inheritdoc />
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            //create our request tracking object
            var tracker = new WebApiRequestMetric(actionContext);

            //If this is a Loupe client request then we don't want to log that (unless we're in debug mode)
            tracker.Suppress = (_enableDebugMode == false) && (_urlCheck.IsLoupeUrl(actionContext));

            // Store this on the request
            actionContext.Request.Store(tracker);

            //And log the request
            if (_configuration.LogRequests &&
                (tracker.Suppress == false))
            {
                var caption        = string.Format("Api {0} {1} Requested", tracker.ControllerName, tracker.ActionName);
                var requestLogging = new MonitorRequestLogging(actionContext, _configuration);

                requestLogging.Log(Category, caption, tracker.UserName, tracker);
            }

            base.OnActionExecuting(actionContext);
        }