UriMatcherResponse - 범위 지정됨
URI가 체계, 호스트, 경로, 조각 및 쿼리 매개변수의 존재 여부에 대해 지정된 조건과 일치하는지 여부에 대한 정보를 반환하는 메서드를 제공합니다.
UriMatcher API와 함께 이 API를 사용합니다. 이 API에는 생성자가 없습니다. 대신 UriMatcher - match() 메서드를 사용하여 UriMatcherResponse 개체를 인스턴스화합니다.
UriMatcherResponse API에는 기본적으로 활성화되는 REST API Provider(com.glide.rest) 플러그인이 필요합니다.
이 API는 sn_ws 네임스페이스 내에서 제공됩니다.
UriMatcherResponse - getErrorMessages()
지정된 조건에 대해 URI를 테스트할 때 발생한 오류에 대한 메시지를 반환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 문자열 | 발생한 오류에 대한 설명입니다. 오류가 발생하지 않은 경우 빈 문자열이 반환됩니다. |
이 예에서는 호스트가 일치 기준에 제공되지 않았기 때문에 오류를 반환합니다.
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());
출력:
Error occurred: true
Error message: Hosts rule is null or empty.
UriMatcherResponse - isError()
지정된 기준에 대해 URI를 테스트할 때 오류가 발생했는지 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 |
오류가 발생했는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 예에서는 URI에 쿼리 매개 변수가 포함되어 있기 때문에 오류를 반환합니다. 이 오류는 match() for disallowQueryParameters 에 전달된 인수가 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());
출력:
Error occurred: true
Error message: Query parameters are not allowed for matching.
UriMatcherResponse - isFragmentMatches()
URI가 조각의 기준과 일치하는지 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 |
URI가 조각의 조건과 일치하는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 예제에서는 URI에 허용되는 조각 목록에 없는 조각이 포함되어 있기 때문에 조건과 일치하지 않음을 보여 줍니다.
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());
출력:
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()
URI가 호스트의 조건과 일치하는지 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 |
URI가 호스트의 조건과 일치하는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 예제에서는 URI가 지정된 체계 및 호스트와 일치하는지 확인합니다.
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());
출력:
Is URI a match: true
Is host a match: true
UriMatcherResponse - isMatch()
URI가 지정된 모든 기준과 일치하는지 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 |
URI가 지정된 모든 조건과 일치하는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 예제에서는 URI가 지정된 체계 및 호스트와 일치하는지 확인합니다.
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());
출력:
Is URI a match: true
UriMatcherResponse - isPathMatches()
URI가 경로의 조건과 일치하는지 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 |
URI가 경로의 조건과 일치하는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 예제에서는 URI가 지정된 체계, 호스트 및 경로와 일치하는지 확인합니다.
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());
출력:
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()
URI가 체계의 조건과 일치하는지 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 |
URI가 체계의 조건과 일치하는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 예제에서는 URI가 지정된 체계 및 호스트와 일치하는지 확인합니다.
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());
출력:
Is URI a match: true
Is scheme a match: true