private OutboundRuleResult ProcessOutboundRule(HttpContextBase httpContext, string responseString, OutboundRule outboundRule) { //Log.Debug(this, "Processing inbound rule - requestUri: {0} inboundRule: {1}", originalUri, inboundRule.Name); var ruleResult = new OutboundRuleResult() { OriginalResponseString = responseString, RewrittenResponseString = responseString }; switch (outboundRule.Using) { case Using.ExactMatch: case Using.RegularExpressions: case Using.Wildcards: ruleResult = ProcessRegularExpressionOutboundRule(ruleResult, outboundRule); break; //case Using.Wildcards: // //TODO: Implement Wildcards // throw new NotImplementedException("Using Wildcards has not been implemented"); // break; } //Log.Debug(this, "Processing inbound rule - requestUri: {0} inboundRule: {1} rewrittenUrl: {2}", ruleResult.OriginalUri, inboundRule.Name, ruleResult.RewrittenUri); //ruleResult.ItemId = inboundRule.ItemId; return(ruleResult); }
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 ProcessOutboundRulesResult ProcessContext(HttpContextBase httpContext, string responseString, IEnumerable <OutboundRule> outboundRules) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } if (outboundRules == null) { throw new ArgumentNullException("outboundRules"); } // process outbound rules here... only set up event if it matches rules and preconditions var processedResults = new List <OutboundRuleResult>(); var ruleResult = new OutboundRuleResult() { RewrittenResponseString = responseString }; foreach (var outboundRule in outboundRules) { ruleResult = ProcessOutboundRule(httpContext, ruleResult.RewrittenResponseString, outboundRule); processedResults.Add(ruleResult); if (!ruleResult.RuleMatched) { continue; } if (ruleResult.RuleMatched && ruleResult.StopProcessing) { break; } } // check rule matches // check conditions var result = new ProcessOutboundRulesResult(processedResults); return(result); }