diff --git a/sdk/core/core-client-rest/CHANGELOG.md b/sdk/core/core-client-rest/CHANGELOG.md index 0a0382bfc524..1a8244fd574b 100644 --- a/sdk/core/core-client-rest/CHANGELOG.md +++ b/sdk/core/core-client-rest/CHANGELOG.md @@ -1,11 +1,12 @@ # Release History -## 1.1.4 (Unreleased) +## 1.1.4 (2023-07-06) ### Features Added - Add `timeout`, `onUploadProgress`, `onDownloadProgress`, `abortSignal`, `tracingOptions`, `onResponse` in the `RequestParameters` for better RLC user experience. - Add `OperationOptions` for better modular user experience. +- Correctly handle `allowInsecureConnection` handling when `undefined` is passed in `RequestParameters`. See https://github.com/Azure/autorest.typescript/issues/1916 for details. ## 1.1.3 (2023-05-04) diff --git a/sdk/core/core-client-rest/src/getClient.ts b/sdk/core/core-client-rest/src/getClient.ts index 72cb1c047dfa..5240c6f4cfbc 100644 --- a/sdk/core/core-client-rest/src/getClient.ts +++ b/sdk/core/core-client-rest/src/getClient.ts @@ -162,13 +162,14 @@ function buildOperation( allowInsecureConnection?: boolean, httpClient?: HttpClient ): StreamableMethod { + allowInsecureConnection = options.allowInsecureConnection ?? allowInsecureConnection; return { then: function (onFulfilled, onrejected) { return sendRequest( method, url, pipeline, - { allowInsecureConnection, ...options }, + { ...options, allowInsecureConnection }, httpClient ).then(onFulfilled, onrejected); }, @@ -177,7 +178,7 @@ function buildOperation( method, url, pipeline, - { allowInsecureConnection, ...options }, + { ...options, allowInsecureConnection }, httpClient ); }, @@ -186,7 +187,7 @@ function buildOperation( method, url, pipeline, - { allowInsecureConnection, ...options }, + { ...options, allowInsecureConnection }, httpClient ); }, diff --git a/sdk/core/core-client-rest/test/getClient.spec.ts b/sdk/core/core-client-rest/test/getClient.spec.ts index dbb0bf6d2cca..72d4bda184a1 100644 --- a/sdk/core/core-client-rest/test/getClient.spec.ts +++ b/sdk/core/core-client-rest/test/getClient.spec.ts @@ -6,6 +6,7 @@ import { getCachedDefaultHttpsClient } from "../src/clientHelpers"; import { getClient } from "../src/getClient"; import sinon from "sinon"; import { + HttpClient, PipelinePolicy, PipelineRequest, PipelineResponse, @@ -200,4 +201,40 @@ describe("getClient", () => { assert.isTrue(policies.indexOf(policy2) < policies.indexOf(retryPolicy)); assert.isTrue(policies.indexOf(retryPolicy) < policies.indexOf(policy1)); }); + + it("should use the client setting for `allowInsecureConnection` when the request setting is undefined", async () => { + const fakeHttpClient: HttpClient = { + sendRequest: async (request) => { + assert.isTrue(request.allowInsecureConnection); + return { headers: createHttpHeaders(), status: 200, request }; + }, + }; + + const client = getClient("https://example.org", { + allowInsecureConnection: true, + httpClient: fakeHttpClient, + }); + + await client.pathUnchecked("/foo").get({ + allowInsecureConnection: undefined, + }); + }); + + it("should not use the client setting for `allowInsecureConnection` when the request setting is false", async () => { + const fakeHttpClient: HttpClient = { + sendRequest: async (request) => { + assert.isFalse(request.allowInsecureConnection); + return { headers: createHttpHeaders(), status: 200, request }; + }, + }; + + const client = getClient("https://example.org", { + allowInsecureConnection: true, + httpClient: fakeHttpClient, + }); + + await client.pathUnchecked("/foo").get({ + allowInsecureConnection: false, + }); + }); });