diff --git a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/PlaybackClient.java b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/PlaybackClient.java index c0ac79146415a..493eb0983d91a 100644 --- a/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/PlaybackClient.java +++ b/sdk/core/azure-core-test/src/main/java/com/azure/core/test/http/PlaybackClient.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; +import java.util.regex.Pattern; /** * HTTP client that plays back {@link NetworkCallRecord NetworkCallRecords}. @@ -28,6 +29,10 @@ public final class PlaybackClient implements HttpClient { private static final String X_MS_CLIENT_REQUEST_ID = "x-ms-client-request-id"; private static final String X_MS_ENCRYPTION_KEY_SHA256 = "x-ms-encryption-key-sha256"; + + // Pattern that matches all '//' in a URL that aren't prefixed by 'http:' or 'https:'. + private static final Pattern DOUBLE_SLASH_CLEANER = Pattern.compile("(? textReplacementRules; @@ -61,8 +66,20 @@ private Mono playbackHttpResponse(final HttpRequest request) { final String matchingUrl = removeHost(incomingUrl); - NetworkCallRecord networkCallRecord = recordedData.findFirstAndRemoveNetworkCall(record -> - record.getMethod().equalsIgnoreCase(incomingMethod) && removeHost(record.getUri()).equalsIgnoreCase(matchingUrl)); + NetworkCallRecord networkCallRecord = recordedData.findFirstAndRemoveNetworkCall(record -> { + if (!record.getMethod().equalsIgnoreCase(incomingMethod)) { + return false; + } + + String removedHostUri = removeHost(record.getUri()); + + // There is an upcoming change in azure-core to fix a scenario with '//' being used instead of '/'. + // For now both recording formats need to be supported. + String cleanedHostUri = DOUBLE_SLASH_CLEANER.matcher(removedHostUri).replaceAll("/"); + String cleanedMatchingUrl = DOUBLE_SLASH_CLEANER.matcher(matchingUrl).replaceAll("/"); + + return cleanedHostUri.equalsIgnoreCase(cleanedMatchingUrl); + }); count.incrementAndGet(); diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/RestProxy.java b/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/RestProxy.java index 6e6752d77eb85..4e1bf7b482c37 100644 --- a/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/RestProxy.java +++ b/sdk/core/azure-core/src/main/java/com/azure/core/http/rest/RestProxy.java @@ -229,7 +229,11 @@ private HttpRequest createHttpRequest(SwaggerMethodParser methodParser, Object[] if (hostPath == null || hostPath.isEmpty() || "/".equals(hostPath) || path.contains("://")) { urlBuilder.setPath(path); } else { - urlBuilder.setPath(hostPath + "/" + path); + if (path.startsWith("/")) { + urlBuilder.setPath(hostPath + path); + } else { + urlBuilder.setPath(hostPath + "/" + path); + } } } }