UriMatcherResponse - Scoped

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:11分
  • 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.

    表 : 1. Parameters
    Name Type Description
    None
    表 : 2. Returns
    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.

    表 : 3. Parameters
    Name Type Description
    None
    表 : 4. Returns
    Type Description
    Boolean

    Flag that indicates whether an error occurred.

    Valid values:
    • true: An error occurred.
    • false: No errors occurred.

    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.

    表 : 5. Parameters
    Name Type Description
    None
    表 : 6. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for fragments.

    Valid values:
    • true: The URI matches the criteria for fragments.
    • false: The URI doesn't match the criteria for fragments.

    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.

    表 : 7. Parameters
    Name Type Description
    None
    表 : 8. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for the host.

    Valid values:
    • true: The URI matches the criteria for the host.
    • false: The URI doesn't match the criteria for the host.

    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.

    表 : 9. Parameters
    Name Type Description
    None
    表 : 10. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches all of the specified criteria.

    Valid values:
    • true: The URI matches all of the criteria.
    • false: The URI doesn't match all of the criteria.

    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.

    表 : 11. Parameters
    Name Type Description
    None
    表 : 12. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for the path.

    Valid values:
    • true: The URI matches the criteria for the path.
    • false: The URI doesn't match the criteria for the path.

    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.

    表 : 13. Parameters
    Name Type Description
    None
    表 : 14. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for the scheme.

    Valid values:
    • true: The URI matches the criteria for the scheme.
    • false: The URI doesn't match the criteria for the scheme.

    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