private OutboundRuleResult ProcessRegularExpressionOutboundRule(OutboundRuleResult ruleResult, OutboundRule outboundRule) { Match outboundRuleMatch, lastConditionMatch = null; // test rule match var isRuleMatch = true; ConditionMatchResult conditionMatchResult = null; // test conditions matches if (outboundRule.Conditions != null && outboundRule.Conditions.Any()) { var replacements = new RewriteHelper.Replacements { RequestHeaders = RequestHeaders, RequestServerVariables = RequestServerVariables, ResponseHeaders = ResponseHeaders }; conditionMatchResult = RewriteHelper.TestConditionMatches(outboundRule, replacements, out lastConditionMatch); isRuleMatch = conditionMatchResult.Matched; } if (isRuleMatch) { ruleResult.RewrittenResponseString = ProcessRuleReplacements(ruleResult.OriginalResponseString, outboundRule); ruleResult.RuleMatched = true; } return(ruleResult); }
public ConditionMatchResult MatchesCondition(Condition condition, ConditionMatchResult result) { if (condition == null) { return(result.Append(ConditionMatch.GeneralMatch)); } return(condition.MatchesConditions(result, this)); }
public override ConditionMatchResult MatchesConditions(ConditionMatchResult result, ContextHolder context) { if (context == null) { return(result); } var superMatches = base.MatchesConditions(result, context); return(AppContext.MatchesCondition(superMatches, context)); }
public ConditionMatchResult MatchesCondition(ConditionMatchResult result, ContextHolder context) { var c = context.ApplicationLookupContext; if (c == null) { c = new ApplicationLookupContext(); } return(result.AppendMetadataMatch(MetadataId, c.MetadataId).Append( con.Calculate(Schema, c.Schema)).Append( con.Calculate(Mode, c.Mode)).Append( con.Calculate(ParentApplication, c.ParentApplication)).Append( con.Calculate(ParentSchema, c.ParentSchema)).Append( con.Calculate(ParentMode, c.ParentMode)).Append( con.Calculate(AttributeName, c.AttributeName))); }
private InboundRuleResult ProcessRegularExpressionInboundRule(Uri originalUri, InboundRule inboundRule) { var ruleResult = new InboundRuleResult { OriginalUri = originalUri, RewrittenUri = originalUri }; Match inboundRuleMatch, lastConditionMatch = null; // test rule match var isInboundRuleMatch = TestRuleMatches(inboundRule, originalUri, out inboundRuleMatch); ConditionMatchResult conditionMatchResult = null; // test conditions matches if (isInboundRuleMatch && inboundRule.Conditions != null && inboundRule.Conditions.Any()) { var replacements = new RewriteHelper.Replacements { RequestHeaders = RequestHeaders, RequestServerVariables = RequestServerVariables }; conditionMatchResult = RewriteHelper.TestConditionMatches(inboundRule, replacements, out lastConditionMatch); isInboundRuleMatch = conditionMatchResult.Matched; } // test site name restrictions if (isInboundRuleMatch && !string.IsNullOrEmpty(inboundRule.SiteNameRestriction)) { isInboundRuleMatch = TestSiteNameRestriction(inboundRule); } if (isInboundRuleMatch && inboundRule.Action != null) { ruleResult.RuleMatched = true; if (inboundRule.ResponseHeaders.Any()) { ruleResult.ResponseHeaders = inboundRule.ResponseHeaders; } Log.Debug(this, "INBOUND RULE MATCH - requestUri: {0} inboundRule: {1}", originalUri, inboundRule.Name); // TODO: Need to implement Rewrite, None if (inboundRule.Action is Redirect) { ProcessRedirectAction(inboundRule, originalUri, inboundRuleMatch, lastConditionMatch, ruleResult); } else if (inboundRule.Action is Rewrite) { ProcessRewriteAction(inboundRule, originalUri, inboundRuleMatch, lastConditionMatch, ruleResult); } else if (inboundRule.Action is ItemQueryRedirect) { ProcessItemQueryRedirectAction(inboundRule, originalUri, inboundRuleMatch, lastConditionMatch, ruleResult); } else if (inboundRule.Action is AbortRequest || inboundRule.Action is CustomResponse) { ProcessActionProcessing(ruleResult); } else { throw new NotImplementedException("Redirect Action, Custome Response and Abort Reqeust Action are the only supported type of redirects"); } ruleResult.ResultAction = inboundRule.Action; ruleResult.ConditionMatchResult = conditionMatchResult; } else if (inboundRule.Action == null) { Log.Warn(this, "Inbound Rule has no Action set - inboundRule: {0} inboundRule ItemId: {1}", inboundRule.Name, inboundRule.ItemId); // we are going to skip this because we don't know what to do with it during processing ruleResult.RuleMatched = false; } return(ruleResult); }
public static ConditionMatchResult TestConditionMatches(IConditionsProperties rule, Replacements replacements, out Match lastConditionMatch) { var conditionMatchResult = new ConditionMatchResult(); bool conditionMatches; lastConditionMatch = null; var conditionLogicalGrouping = rule.ConditionLogicalGrouping.HasValue ? rule.ConditionLogicalGrouping.Value : LogicalGrouping.MatchAll; conditionMatchResult.LogincalGrouping = conditionLogicalGrouping; if (conditionLogicalGrouping == LogicalGrouping.MatchAll) { foreach (var condition in rule.Conditions) { var conditionMatched = TestConditionMatch(replacements, condition, lastConditionMatch); var conditionMatch = conditionMatched.Match; var conditionInput = conditionMatched.ConditionInput; conditionMatches = conditionMatch.Success; if (condition.CheckIfInputString != null && condition.CheckIfInputString.Value == CheckIfInputString.DoesNotMatchThePattern) { conditionMatches = !conditionMatches; } if (conditionMatches) { lastConditionMatch = conditionMatch; conditionMatchResult.MatchedConditions.Add(new MatchedCondition(condition, conditionInput)); conditionMatchResult.Matched = true; } else { conditionMatchResult.Matched = false; break; } } } else { foreach (var condition in rule.Conditions) { var conditionMatched = TestConditionMatch(replacements, condition); var conditionMatch = conditionMatched.Match; var conditionInput = conditionMatched.ConditionInput; conditionMatches = conditionMatch.Success; if (condition.CheckIfInputString != null && condition.CheckIfInputString.Value == CheckIfInputString.DoesNotMatchThePattern) { conditionMatches = !conditionMatches; } if (!conditionMatches) { continue; } conditionMatchResult.MatchedConditions.Add(new MatchedCondition(condition, conditionInput)); lastConditionMatch = conditionMatch; conditionMatchResult.Matched = true; break; } } return(conditionMatchResult); }