diff --git a/sdk/core/core-rest-pipeline/CHANGELOG.md b/sdk/core/core-rest-pipeline/CHANGELOG.md index e1cf586227dd..334fd4e8be5b 100644 --- a/sdk/core/core-rest-pipeline/CHANGELOG.md +++ b/sdk/core/core-rest-pipeline/CHANGELOG.md @@ -11,6 +11,7 @@ ### Bugs Fixed - Updated `redirectPolicy` to remove the `Authorization` header from redirected requests. [#21026](https://github.com/Azure/azure-sdk-for-js/pull/21026) +- Fixed an issue introduced in 1.6.0 where redirects were not properly followed in the browser. [#21051](https://github.com/Azure/azure-sdk-for-js/pull/21051) ### Other Changes diff --git a/sdk/core/core-rest-pipeline/src/createPipelineFromOptions.ts b/sdk/core/core-rest-pipeline/src/createPipelineFromOptions.ts index 8ab67fd8dd14..54f5d6f01d53 100644 --- a/sdk/core/core-rest-pipeline/src/createPipelineFromOptions.ts +++ b/sdk/core/core-rest-pipeline/src/createPipelineFromOptions.ts @@ -69,7 +69,11 @@ export function createPipelineFromOptions(options: InternalPipelineOptions): Pip pipeline.addPolicy(setClientRequestIdPolicy()); pipeline.addPolicy(defaultRetryPolicy(options.retryOptions), { phase: "Retry" }); pipeline.addPolicy(tracingPolicy(options.userAgentOptions), { afterPhase: "Retry" }); - pipeline.addPolicy(redirectPolicy(options.redirectOptions), { afterPhase: "Retry" }); + if (isNode) { + // Both XHR and Fetch expect to handle redirects automatically, + // so only include this policy when we're in Node. + pipeline.addPolicy(redirectPolicy(options.redirectOptions), { afterPhase: "Retry" }); + } pipeline.addPolicy(logPolicy(options.loggingOptions), { afterPhase: "Retry" }); return pipeline; diff --git a/sdk/core/core-rest-pipeline/src/fetchHttpClient.ts b/sdk/core/core-rest-pipeline/src/fetchHttpClient.ts index d540427c1b71..6f26b9c4e21f 100644 --- a/sdk/core/core-rest-pipeline/src/fetchHttpClient.ts +++ b/sdk/core/core-rest-pipeline/src/fetchHttpClient.ts @@ -69,13 +69,18 @@ async function makeRequest(request: PipelineRequest): Promise const headers = buildFetchHeaders(request.headers); const requestBody = buildRequestBody(request); + /** + * Developers of the future: + * Do not set redirect: "manual" as part + * of request options. + * It will not work as you expect. + */ const response = await fetch(request.url, { body: requestBody, method: request.method, headers: headers, signal: abortController.signal, credentials: request.withCredentials ? "include" : "same-origin", - redirect: "manual", cache: "no-store", }); return buildPipelineResponse(response, request); diff --git a/sdk/core/core-rest-pipeline/src/policies/redirectPolicy.ts b/sdk/core/core-rest-pipeline/src/policies/redirectPolicy.ts index ece9796997ab..28d0f4074fbc 100644 --- a/sdk/core/core-rest-pipeline/src/policies/redirectPolicy.ts +++ b/sdk/core/core-rest-pipeline/src/policies/redirectPolicy.ts @@ -29,6 +29,7 @@ export interface RedirectPolicyOptions { /** * A policy to follow Location headers from the server in order * to support server-side redirection. + * In the browser, this policy is not used. * @param options - Options to control policy behavior. */ export function redirectPolicy(options: RedirectPolicyOptions = {}): PipelinePolicy {