matchUrl static method
Match a URL against registered patterns. Matches against both the full URL and just the path portion.
Implementation
static MockResponse? matchUrl(String url, {String method = 'GET'}) {
// Try matching against both the full URL and just the path
final urlPath = Uri.parse(url).path;
for (final pattern in _urlPatterns.reversed) {
if (pattern.method != method.toUpperCase()) continue;
// Match against full URL first, then path only
if (_matchPattern(pattern.pattern, url) ||
_matchPattern(pattern.pattern, urlPath)) {
return MockResponse(
data: pattern.response,
statusCode: pattern.statusCode,
headers: pattern.headers,
delay: pattern.delay,
);
}
}
return null;
}