UriMatcherResponse - Scoped
Provides methods to return information about whether a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.
Use this API with the UriMatcher API. This API doesn't have a constructor. Instead, use the UriMatcher - match() method to instantiate a UriMatcherResponse object.
The UriMatcherResponse API requires the REST API Provider (com.glide.rest) plugin, which is activated by default.
This API is provided within the sn_ws namespace.
UriMatcherResponse - getErrorMessages()
Returns messages about any errors that occurred when testing the URI against the specified criteria.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| String | Description of the error that occurred. If no error occurred, an empty string is returned. |
This example returns an error because a host wasn't provided in the matching criteria.
var uri = "https://example.com";
var scheme = "https";
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme);
gs.info("Error occurred: " + resp.isError());
gs.info("Error message: " + resp.getErrorMessages());
Output:
Error occurred: true
Error message: Hosts rule is null or empty.
UriMatcherResponse - isError()
Checks if an error occurred when testing the URI against the specified criteria.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean |
Flag that indicates whether an error occurred. Valid values:
|
This example returns an error because the URI contains query parameters. The error occurs because the argument passed to match() for disallowQueryParameters is true.
var uri = "https://example.com/path1/more?q=query";
var scheme = "https";
var allowedHosts = ["example.com", "sample.com"];
var allowedPaths = ["/path1/more", "/path2/less"];
var allowedFragments = ["section1", "section2"];
var noQueryParams = true;
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments, noQueryParams);
gs.info("Error occurred: " + resp.isError());
gs.info("Error message: " + resp.getErrorMessages());
Output:
Error occurred: true
Error message: Query parameters are not allowed for matching.
UriMatcherResponse - isFragmentMatches()
Checks if the URI matches the criteria for fragments.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean |
Flag that indicates whether the URI matches the criteria for fragments. Valid values:
|
This example shows that the URI doesn't match the criteria because it contains a fragment that isn't in the list of allowed fragments.
var uri = "https://example.com/path1/more#section3";
var scheme = "https";
var allowedHosts = ["example.com", "sample.com"];
var allowedPaths = ["/path1/more", "/path2/less"];
var allowedFragments = ["section1", "section2"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is scheme a match: " + resp.isSchemeMatches());
gs.info("Is host a match: " + resp.isHostMatches());
gs.info("Is path a match: " + resp.isPathMatches());
gs.info("Is fragment a match: " + resp.isFragmentMatches());
gs.info("Error occurred: " + resp.isError());
Output:
Is URI a match: false
Is scheme a match: true
Is host a match: true
Is path a match: true
Is fragment a match: false
Error occurred: false
UriMatcherResponse - isHostMatches()
Checks if the URI matches the criteria for the host.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean |
Flag that indicates whether the URI matches the criteria for the host. Valid values:
|
This example checks if the URI matches the specified scheme and host.
var uri = "https://example.com/path?q=query";
var scheme = "https";
var allowedHosts = ["example.com"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is host a match: " + resp.isHostMatches());
Output:
Is URI a match: true
Is host a match: true
UriMatcherResponse - isMatch()
Checks if the URI matches all of the specified criteria.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean |
Flag that indicates whether the URI matches all of the specified criteria. Valid values:
|
This example checks if the URI matches the specified scheme and host.
var uri = "https://example.com/path?q=query";
var scheme = "https";
var allowedHosts = ["example.com"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts);
gs.info("Is URI a match: " + resp.isMatch());
Output:
Is URI a match: true
UriMatcherResponse - isPathMatches()
Checks if the URI matches the criteria for the path.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean |
Flag that indicates whether the URI matches the criteria for the path. Valid values:
|
This example checks if the URI matches the specified scheme, host, and path.
var uri = "https://example.com/path1/more";
var scheme = "https";
var allowedHosts = ["example.com", "sample.com"];
var allowedPaths = ["/path1/more", "/path2/less"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is scheme a match: " + resp.isSchemeMatches());
gs.info("Is host a match: " + resp.isHostMatches());
gs.info("Is path a match: " + resp.isPathMatches());
gs.info("Is fragment a match: " + resp.isFragmentMatches());
gs.info("Error occurred: " + resp.isError());
Output:
Is URI a match: true
Is scheme a match: true
Is host a match: true
Is path a match: true
Is fragment a match: true
Error occurred: false
UriMatcherResponse - isSchemeMatches()
Checks if the URI matches the criteria for the scheme.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean |
Flag that indicates whether the URI matches the criteria for the scheme. Valid values:
|
This example checks if the URI matches the specified scheme and host.
var uri = "https://example.com/path?q=query";
var scheme = "https";
var allowedHosts = ["example.com"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is scheme a match: " + resp.isSchemeMatches());
Output:
Is URI a match: true
Is scheme a match: true