Esempio n. 1
0
        public void Initialize()
        {
            _request1 = new MockRequestInfo("/path1/path2?param=value", "http", "test.com", 80);
            _request2 = new MockRequestInfo("/path1/path2", "https", "secure.test.com", 443);
            _request3 = new MockRequestInfo("/path1/path2/", "http", "test.com", 80);

            _request1.NewPath[1]             = "changed1";
            _request1.NewParameters["param"] = new List <string> {
                "changed"
            };
            _request1.PathChanged();
            _request1.SetServerVariable("PATH_INFO", "/company/news/");
            _request1.SetHeader("HOST", "www.mysite.com");

            _request2.NewPath[2] = "changed2";
            _request2.PathChanged();
            _request2.SetServerVariable("SERVER_PORT", "443");
            _request2.SetHeader("USER_AGENT", "blah blah blah");

            _request3.NewUrlString           = "/changed1/changed2/";
            _request3.NewParameters["param"] = new List <string> {
                "added"
            };
            _request3.ParametersChanged();

            IFactory factory = new NinjectFactory();

            _valueGetter = factory.Create <IValueGetter>();
            _ruleResult  = factory.Create <IRuleResult>();
        }
Esempio n. 2
0
        public override void PerformAction(
            IRequestInfo requestInfo,
            IRuleResult ruleResult,
            out bool stopProcessing,
            out bool endRequest)
        {
            var value = _valueGetter.GetString(requestInfo, ruleResult);

            switch (_scope)
            {
            case Scope.Url:
                requestInfo.NewUrlString = value;
                break;

            case Scope.Path:
                requestInfo.NewPathString = value;
                break;

            case Scope.QueryString:
                requestInfo.NewParametersString = value;
                break;

            case Scope.Header:
                requestInfo.SetHeader(_scopeIndex, value);
                break;

            case Scope.Parameter:
                requestInfo.NewParameters[_scopeIndex] = new List <string> {
                    value
                };
                requestInfo.ParametersChanged();
                break;

            case Scope.PathElement:
                if (_scopeIndexValue == 0)
                {
                    requestInfo.NewPathString = value;
                }
                else if (_scopeIndexValue > 0)
                {
                    var count = requestInfo.NewPath.Count;
                    if (string.IsNullOrEmpty(requestInfo.NewPath[count - 1]))
                    {
                        count--;
                    }
                    if (_scopeIndexValue < count)
                    {
                        requestInfo.NewPath[_scopeIndexValue] = value;
                        requestInfo.PathChanged();
                    }
                }
                else
                {
                    var count = requestInfo.NewPath.Count;
                    if (string.IsNullOrEmpty(requestInfo.NewPath[count - 1]))
                    {
                        count--;
                    }
                    var index = count + _scopeIndexValue;
                    if (index > 0)
                    {
                        requestInfo.NewPath[index] = value;
                        requestInfo.PathChanged();
                    }
                }
                break;

            case Scope.ServerVariable:
                requestInfo.SetServerVariable(_scopeIndex, value);
                break;
            }

            stopProcessing = _stopProcessing;
            endRequest     = _endRequest;
        }
Esempio n. 3
0
        public override void PerformAction(
            IRequestInfo requestInfo,
            IRuleResult ruleResult,
            out bool stopProcessing,
            out bool endRequest)
        {
            var value = _valueGetter.GetString(requestInfo, ruleResult);

            switch (_scope)
            {
            case Scope.Url:
                requestInfo.NewUrlString = requestInfo.NewUrlString + value;
                break;

            case Scope.Path:
                requestInfo.NewPathString = requestInfo.NewPathString
                                            + (requestInfo.NewPathString.EndsWith("/") ? "" : "/") + value;
                break;

            case Scope.QueryString:
                if (!string.IsNullOrWhiteSpace(value))
                {
                    requestInfo.NewParametersString = requestInfo.NewParametersString
                                                      + (requestInfo.NewParametersString.Length > 0 ? "&" : "") + value;
                }
                break;

            case Scope.Header:
                requestInfo.SetHeader(_scopeIndex, requestInfo.GetHeader(_scopeIndex) + value);
                break;

            case Scope.Parameter:
                requestInfo.NewParameters[_scopeIndex].Add(value);
                requestInfo.ParametersChanged();
                break;

            case Scope.PathElement:
            {
                var count = requestInfo.NewPath.Count;
                if (string.IsNullOrEmpty(requestInfo.NewPath[count - 1]))
                {
                    count--;
                }
                if (_scopeIndexValue > 0)
                {
                    if (_scopeIndexValue < count)
                    {
                        requestInfo.NewPath[_scopeIndexValue] = requestInfo.NewPath[_scopeIndexValue] + value;
                        requestInfo.PathChanged();
                    }
                }
                else
                {
                    var index = count + _scopeIndexValue;
                    if (index > 0)
                    {
                        requestInfo.NewPath[index] = requestInfo.NewPath[index] + value;
                        requestInfo.PathChanged();
                    }
                }
                requestInfo.PathChanged();
                break;
            }

            case Scope.ServerVariable:
                requestInfo.SetServerVariable(_scopeIndex, requestInfo.GetServerVariable(_scopeIndex) + value);
                break;
            }

            stopProcessing = _stopProcessing;
            endRequest     = _endRequest;
        }
Esempio n. 4
0
        public override void PerformAction(
            IRequestInfo requestInfo,
            IRuleResult ruleResult,
            out bool stopProcessing,
            out bool endRequest)
        {
            switch (_scope)
            {
            case Scope.Url:
                requestInfo.NewUrlString = "/";
                break;

            case Scope.Path:
                requestInfo.NewPathString = "/";
                break;

            case Scope.QueryString:
                requestInfo.NewParametersString = string.Empty;
                break;

            case Scope.Header:
                requestInfo.SetHeader(_scopeIndex, null);
                break;

            case Scope.Parameter:
                requestInfo.NewParameters.Remove(_scopeIndex);
                requestInfo.ParametersChanged();
                break;

            case Scope.PathElement:
            {
                if (_scopeIndexValue == 0 || requestInfo.NewPathString == "/")
                {
                    requestInfo.NewPathString = "/";
                }
                else
                {
                    var count = requestInfo.NewPath.Count;
                    if (string.IsNullOrEmpty(requestInfo.NewPath[count - 1]))
                    {
                        count--;
                    }
                    var indexToRemove = _scopeIndexValue < 0
                            ? count + _scopeIndexValue
                            : _scopeIndexValue;
                    if (indexToRemove > 0 && indexToRemove < count)
                    {
                        requestInfo.NewPath.RemoveAt(indexToRemove);
                        requestInfo.PathChanged();
                    }
                }
                break;
            }

            case Scope.ServerVariable:
                requestInfo.SetServerVariable(_scopeIndex, null);
                break;
            }

            stopProcessing = _stopProcessing;
            endRequest     = _endRequest;
        }