mirror of https://github.com/grpc/grpc-node.git
Merge pull request #2462 from murgatroid99/grpc-js-xds_header_match_string_match
grpc-js-xds: Support string_match in header matching
This commit is contained in:
commit
2a11a2c18f
|
@ -37,14 +37,19 @@ export interface ValueMatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ExactValueMatcher implements ValueMatcher {
|
export class ExactValueMatcher implements ValueMatcher {
|
||||||
constructor(private targetValue: string) {}
|
constructor(private targetValue: string, private ignoreCase: boolean) {
|
||||||
|
}
|
||||||
|
|
||||||
apply(value: string) {
|
apply(value: string) {
|
||||||
return value === this.targetValue;
|
if (this.ignoreCase) {
|
||||||
|
return value.toLowerCase() === this.targetValue.toLowerCase();
|
||||||
|
} else {
|
||||||
|
return value === this.targetValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return 'Exact(' + this.targetValue + ')';
|
return 'Exact(' + this.targetValue + ', ignore_case=' + this.ignoreCase + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,26 +99,51 @@ export class PresentValueMatcher implements ValueMatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PrefixValueMatcher implements ValueMatcher {
|
export class PrefixValueMatcher implements ValueMatcher {
|
||||||
constructor(private prefix: string) {}
|
constructor(private prefix: string, private ignoreCase: boolean) {
|
||||||
|
}
|
||||||
|
|
||||||
apply(value: string) {
|
apply(value: string) {
|
||||||
return value.startsWith(this.prefix);
|
if (this.ignoreCase) {
|
||||||
|
return value.toLowerCase().startsWith(this.prefix.toLowerCase());
|
||||||
|
} else {
|
||||||
|
return value.startsWith(this.prefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return 'Prefix(' + this.prefix + ')';
|
return 'Prefix(' + this.prefix + ', ignore_case=' + this.ignoreCase + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SuffixValueMatcher implements ValueMatcher {
|
export class SuffixValueMatcher implements ValueMatcher {
|
||||||
constructor(private suffix: string) {}
|
constructor(private suffix: string, private ignoreCase: boolean) {}
|
||||||
|
|
||||||
apply(value: string) {
|
apply(value: string) {
|
||||||
return value.endsWith(this.suffix);
|
if (this.ignoreCase) {
|
||||||
|
return value.toLowerCase().endsWith(this.suffix.toLowerCase());
|
||||||
|
} else {
|
||||||
|
return value.endsWith(this.suffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return 'Suffix(' + this.suffix + ')';
|
return 'Suffix(' + this.suffix + ', ignore_case=' + this.ignoreCase + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ContainsValueMatcher implements ValueMatcher {
|
||||||
|
constructor(private contains: string, private ignoreCase: boolean) {}
|
||||||
|
|
||||||
|
apply(value: string) {
|
||||||
|
if (this.ignoreCase) {
|
||||||
|
return value.toLowerCase().includes(this.contains.toLowerCase());
|
||||||
|
} else {
|
||||||
|
return value.includes(this.contains);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return 'Contains(' + this.contains + + ', ignore_case=' + this.ignoreCase + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import { HeaderMatcher__Output } from './generated/envoy/config/route/v3/HeaderM
|
||||||
import ConfigSelector = experimental.ConfigSelector;
|
import ConfigSelector = experimental.ConfigSelector;
|
||||||
import LoadBalancingConfig = experimental.LoadBalancingConfig;
|
import LoadBalancingConfig = experimental.LoadBalancingConfig;
|
||||||
import { XdsClusterManagerLoadBalancingConfig } from './load-balancer-xds-cluster-manager';
|
import { XdsClusterManagerLoadBalancingConfig } from './load-balancer-xds-cluster-manager';
|
||||||
import { ExactValueMatcher, FullMatcher, HeaderMatcher, Matcher, PathExactValueMatcher, PathPrefixValueMatcher, PathSafeRegexValueMatcher, PrefixValueMatcher, PresentValueMatcher, RangeValueMatcher, RejectValueMatcher, SafeRegexValueMatcher, SuffixValueMatcher, ValueMatcher } from './matcher';
|
import { ContainsValueMatcher, ExactValueMatcher, FullMatcher, HeaderMatcher, Matcher, PathExactValueMatcher, PathPrefixValueMatcher, PathSafeRegexValueMatcher, PrefixValueMatcher, PresentValueMatcher, RangeValueMatcher, RejectValueMatcher, SafeRegexValueMatcher, SuffixValueMatcher, ValueMatcher } from './matcher';
|
||||||
import { envoyFractionToFraction, Fraction } from "./fraction";
|
import { envoyFractionToFraction, Fraction } from "./fraction";
|
||||||
import { RouteAction, SingleClusterRouteAction, WeightedCluster, WeightedClusterRouteAction } from './route-action';
|
import { RouteAction, SingleClusterRouteAction, WeightedCluster, WeightedClusterRouteAction } from './route-action';
|
||||||
import { decodeSingleResource, HTTP_CONNECTION_MANGER_TYPE_URL } from './resources';
|
import { decodeSingleResource, HTTP_CONNECTION_MANGER_TYPE_URL } from './resources';
|
||||||
|
@ -136,7 +136,7 @@ function getPredicateForHeaderMatcher(headerMatch: HeaderMatcher__Output): Match
|
||||||
let valueChecker: ValueMatcher;
|
let valueChecker: ValueMatcher;
|
||||||
switch (headerMatch.header_match_specifier) {
|
switch (headerMatch.header_match_specifier) {
|
||||||
case 'exact_match':
|
case 'exact_match':
|
||||||
valueChecker = new ExactValueMatcher(headerMatch.exact_match!);
|
valueChecker = new ExactValueMatcher(headerMatch.exact_match!, false);
|
||||||
break;
|
break;
|
||||||
case 'safe_regex_match':
|
case 'safe_regex_match':
|
||||||
valueChecker = new SafeRegexValueMatcher(headerMatch.safe_regex_match!.regex);
|
valueChecker = new SafeRegexValueMatcher(headerMatch.safe_regex_match!.regex);
|
||||||
|
@ -150,10 +150,30 @@ function getPredicateForHeaderMatcher(headerMatch: HeaderMatcher__Output): Match
|
||||||
valueChecker = new PresentValueMatcher();
|
valueChecker = new PresentValueMatcher();
|
||||||
break;
|
break;
|
||||||
case 'prefix_match':
|
case 'prefix_match':
|
||||||
valueChecker = new PrefixValueMatcher(headerMatch.prefix_match!);
|
valueChecker = new PrefixValueMatcher(headerMatch.prefix_match!, false);
|
||||||
break;
|
break;
|
||||||
case 'suffix_match':
|
case 'suffix_match':
|
||||||
valueChecker = new SuffixValueMatcher(headerMatch.suffix_match!);
|
valueChecker = new SuffixValueMatcher(headerMatch.suffix_match!, false);
|
||||||
|
break;
|
||||||
|
case 'string_match':
|
||||||
|
const stringMatch = headerMatch.string_match!
|
||||||
|
switch (stringMatch.match_pattern) {
|
||||||
|
case 'exact':
|
||||||
|
valueChecker = new ExactValueMatcher(stringMatch.exact!, stringMatch.ignore_case);
|
||||||
|
break;
|
||||||
|
case 'safe_regex':
|
||||||
|
valueChecker = new SafeRegexValueMatcher(stringMatch.safe_regex!.regex);
|
||||||
|
break;
|
||||||
|
case 'prefix':
|
||||||
|
valueChecker = new PrefixValueMatcher(stringMatch.prefix!, stringMatch.ignore_case);
|
||||||
|
break;
|
||||||
|
case 'suffix':
|
||||||
|
valueChecker = new SuffixValueMatcher(stringMatch.suffix!, stringMatch.ignore_case);
|
||||||
|
break;
|
||||||
|
case 'contains':
|
||||||
|
valueChecker = new ContainsValueMatcher(stringMatch.contains!, stringMatch.ignore_case);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
valueChecker = new RejectValueMatcher();
|
valueChecker = new RejectValueMatcher();
|
||||||
|
|
|
@ -29,7 +29,8 @@ const SUPPPORTED_HEADER_MATCH_SPECIFIERS = [
|
||||||
'range_match',
|
'range_match',
|
||||||
'present_match',
|
'present_match',
|
||||||
'prefix_match',
|
'prefix_match',
|
||||||
'suffix_match'];
|
'suffix_match',
|
||||||
|
'string_match'];
|
||||||
const SUPPORTED_CLUSTER_SPECIFIERS = ['cluster', 'weighted_clusters', 'cluster_header'];
|
const SUPPORTED_CLUSTER_SPECIFIERS = ['cluster', 'weighted_clusters', 'cluster_header'];
|
||||||
|
|
||||||
const UINT32_MAX = 0xFFFFFFFF;
|
const UINT32_MAX = 0xFFFFFFFF;
|
||||||
|
|
Loading…
Reference in New Issue