UriMatcher - Scoped
Provides a method to check if a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.
The UriMatcher API requires the REST API Provider (com.glide.rest) plugin, which is activated by default.
This API is provided within the sn_ws namespace.
UriMatcher - UriMatcher()
Instantiates a new UriMatcher object.
| Name | Type | Description |
|---|---|---|
| None |
Instantiates a UriMatcher object.
var matcher = new sn_ws.UriMatcher();
UriMatcher - match(String uri, String scheme, Array hosts, Array paths, Array fragments, Boolean disallowQueryParameters)
Checks if a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.
| Name | Type | Description |
|---|---|---|
| uri | String | URI to test against the specified criteria. |
| scheme | String | Protocol used in the URI. Valid values:
|
| hosts | Array | List of allowed hosts in the URI. The URI must use one of the allowed hosts to be considered a match. |
| paths | Array | Optional. List of allowed paths in the URI. The URI must use one of the allowed paths to be considered a match, and the allowed path must be the full path used in the URI. For example, if the allowed path is
Remarque :
Paths must start with /.Default: Any path is allowed. |
| fragments | Array | Optional. List of allowed fragments in the URI. The URI is considered a match even if it doesn't contain any of the allowed fragments. The URI is only considered not matching if it contains fragments that aren't in the allowed list. Default: Any fragment is allowed. |
| disallowQueryParameters | Boolean | Optional. Flag that indicates whether query parameters are allowed in the URI. Valid values:
Default: false |
| Type | Description |
|---|---|
| UriMatcherResponse | UriMatcherResponse object with methods for returning detailed information about the match. |
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
This example checks if the URI matches the specified scheme, host, path, fragments, and presence of query parameters.
var uri = "https://example.com/path1/more";
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("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());
gs.info("Error message: " + resp.getErrorMessages());
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
Error message: