diff --git a/tools/http-fault-injector/sample-clients/java/storage-blobs/src/main/java/Utils.java b/tools/http-fault-injector/sample-clients/java/storage-blobs/src/main/java/Utils.java index 857fce02f21..4bca821c9f0 100644 --- a/tools/http-fault-injector/sample-clients/java/storage-blobs/src/main/java/Utils.java +++ b/tools/http-fault-injector/sample-clients/java/storage-blobs/src/main/java/Utils.java @@ -59,12 +59,16 @@ public static HttpRequest rewriteUrlToUseFaultInjector(HttpRequest request, Stri URI faultInjectorUri = new URI(scheme, requestUri.getUserInfo(), host, port, requestUri.getPath(), requestUri.getQuery(), requestUri.getFragment()); - String xUpstreamBaseUri = (requestUri.getPort() < 0) - ? requestUri.getScheme() + "://" + requestUri.getHost() - : requestUri.getScheme() + "://" + requestUri.getHost() + ":" + requestUri.getPort(); + // Ensure X-Upstream-Base-Uri header is only set once, since the same HttpMessage will be reused on retries + if (request.getHeaders().get(HTTP_FAULT_INJECTOR_UPSTREAM_BASE_URI_HEADER) == null) { + String xUpstreamBaseUri = (requestUri.getPort() < 0) + ? requestUri.getScheme() + "://" + requestUri.getHost() + : requestUri.getScheme() + "://" + requestUri.getHost() + ":" + requestUri.getPort(); - return request.setHeader(HTTP_FAULT_INJECTOR_UPSTREAM_BASE_URI_HEADER, xUpstreamBaseUri) - .setUrl(faultInjectorUri.toURL()); + request.setHeader(HTTP_FAULT_INJECTOR_UPSTREAM_BASE_URI_HEADER, xUpstreamBaseUri); + } + + return request.setUrl(faultInjectorUri.toURL()); } catch (Exception exception) { throw new IllegalStateException(exception); }