Skip to content

Commit 7a7c173

Browse files
authored
[core-https] Hide client constructors (Azure#13859)
Migrate DefaultHttpsClient from a constructor pattern to a factory.
1 parent 38a2bdd commit 7a7c173

File tree

16 files changed

+62
-40
lines changed

16 files changed

+62
-40
lines changed

sdk/core/core-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"dependencies": {
7979
"@azure/abort-controller": "^1.0.0",
8080
"@azure/core-auth": "^1.2.0",
81-
"@azure/core-https": "1.0.0-beta.1",
81+
"@azure/core-https": "1.0.0-beta.2",
8282
"@azure/core-tracing": "1.0.0-preview.9",
8383
"@opentelemetry/api": "^0.10.2",
8484
"tslib": "^2.0.0"

sdk/core/core-client/src/httpClientCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { HttpsClient, DefaultHttpsClient } from "@azure/core-https";
4+
import { HttpsClient, createDefaultHttpsClient } from "@azure/core-https";
55

66
let cachedHttpsClient: HttpsClient | undefined;
77

88
export function getCachedDefaultHttpsClient(): HttpsClient {
99
if (!cachedHttpsClient) {
10-
cachedHttpsClient = new DefaultHttpsClient();
10+
cachedHttpsClient = createDefaultHttpsClient();
1111
}
1212

1313
return cachedHttpsClient;

sdk/core/core-https/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.0.0-beta.2 (Unreleased)
44

5+
- Changed from exposing `DefaultHttpsClient` as a class directly, to providing `createDefaultHttpsClient()` to instantiate the appropriate runtime class.
6+
57
## 1.0.0-beta.1 (2021-02-04)
68

79
- Changes from `core-http`:

sdk/core/core-https/review/core-https.api.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export interface BearerTokenAuthenticationPolicyOptions {
2929
scopes: string | string[];
3030
}
3131

32+
// @public
33+
export function createDefaultHttpsClient(): HttpsClient;
34+
3235
// @public
3336
export function createEmptyPipeline(): Pipeline;
3437

@@ -47,11 +50,6 @@ export function decompressResponsePolicy(): PipelinePolicy;
4750
// @public
4851
export const decompressResponsePolicyName = "decompressResponsePolicy";
4952

50-
// @public
51-
export class DefaultHttpsClient implements HttpsClient {
52-
sendRequest(request: PipelineRequest): Promise<PipelineResponse>;
53-
}
54-
5553
// @public
5654
export function exponentialRetryPolicy(options?: ExponentialRetryPolicyOptions): PipelinePolicy;
5755

sdk/core/core-https/src/accessTokenCache.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface AccessTokenCache {
3131
* Provides an AccessTokenCache implementation which clears
3232
* the cached AccessToken's after the expiresOnTimestamp has
3333
* passed.
34+
* @internal
3435
*/
3536
export class ExpiringAccessTokenCache implements AccessTokenCache {
3637
private tokenRefreshBufferMs: number;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
export { XhrHttpsClient as DefaultHttpsClient } from "./xhrHttpsClient";
4+
export { createXhrHttpsClient as createDefaultHttpsClient } from "./xhrHttpsClient";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
export { NodeHttpsClient as DefaultHttpsClient } from "./nodeHttpsClient";
4+
export { createNodeHttpsClient as createDefaultHttpsClient } from "./nodeHttpsClient";

sdk/core/core-https/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export {
2525
PipelineOptions,
2626
createPipelineFromOptions
2727
} from "./pipeline";
28-
export { DefaultHttpsClient } from "./defaultHttpsClient";
28+
export { createDefaultHttpsClient } from "./defaultHttpsClient";
2929
export { createHttpHeaders } from "./httpHeaders";
3030
export { createPipelineRequest, PipelineRequestOptions } from "./pipelineRequest";
3131
export { RestError, RestErrorOptions } from "./restError";

sdk/core/core-https/src/nodeHttpsClient.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ class ReportTransform extends Transform {
6060

6161
/**
6262
* A HttpsClient implementation that uses Node's "https" module to send HTTPS requests.
63+
* @internal
6364
*/
64-
export class NodeHttpsClient implements HttpsClient {
65+
class NodeHttpsClient implements HttpsClient {
6566
private keepAliveAgent?: https.Agent;
6667
private proxyAgent?: https.Agent;
6768

@@ -306,3 +307,10 @@ function getBodyLength(body: RequestBodyType): number | null {
306307
return null;
307308
}
308309
}
310+
311+
/**
312+
* Create a new HttpsClient instance for the NodeJS environment.
313+
*/
314+
export function createNodeHttpsClient(): HttpsClient {
315+
return new NodeHttpsClient();
316+
}

sdk/core/core-https/src/xhrHttpsClient.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ function isReadableStream(body: any): body is NodeJS.ReadableStream {
2020

2121
/**
2222
* A HttpsClient implementation that uses XMLHttpRequest to send HTTPS requests.
23+
* @internal
2324
*/
24-
export class XhrHttpsClient implements HttpsClient {
25+
class XhrHttpsClient implements HttpsClient {
2526
/**
2627
* Makes a request over an underlying transport layer and returns the response.
2728
* @param request - The request to be made.
@@ -188,3 +189,10 @@ function rejectOnTerminalEvent(
188189
xhr.addEventListener("abort", () => reject(abortError));
189190
xhr.addEventListener("timeout", () => reject(abortError));
190191
}
192+
193+
/**
194+
* Create a new HttpsClient instance for the browser environment.
195+
*/
196+
export function createXhrHttpsClient(): HttpsClient {
197+
return new XhrHttpsClient();
198+
}

0 commit comments

Comments
 (0)