forked from microsoftgraph/msgraph-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPClientFactory.ts
More file actions
51 lines (47 loc) · 1.88 KB
/
Copy pathHTTPClientFactory.ts
File metadata and controls
51 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module HTTPClientFactory
*/
import { HTTPClient } from "./HTTPClient";
import { AuthenticationProvider } from "./IAuthenticationProvider";
import { AuthenticationHandler } from "./middleware/AuthenticationHandler";
import { HTTPMessageHandler } from "./middleware/HTTPMessageHandler";
import { Middleware } from "./middleware/IMiddleware";
import { RetryHandlerOptions } from "./middleware/options/RetryHandlerOptions";
import { RetryHandler } from "./middleware/RetryHandler";
/**
* @class
* Class representing HTTPClientFactory
*/
export class HTTPClientFactory {
/**
* @public
* @static
* Creates HTTPClient with default middleware chain
* @param {AuthenticationProvider} authProvider - The authentication provider instance
* @returns A HTTPClient instance
*/
public static createWithAuthenticationProvider(authProvider: AuthenticationProvider): HTTPClient {
const authenticationHandler = new AuthenticationHandler(authProvider);
const retryHandler = new RetryHandler(new RetryHandlerOptions());
const httpMessageHandler = new HTTPMessageHandler();
authenticationHandler.setNext(retryHandler);
retryHandler.setNext(httpMessageHandler);
return HTTPClientFactory.createWithMiddleware(authenticationHandler);
}
/**
* @public
* @static
* Creates a middleware chain with the given one
* @param {Middleware} middleware - The first middleware of the middleware chain
* @returns A HTTPClient instance
*/
public static createWithMiddleware(middleware: Middleware): HTTPClient {
return new HTTPClient(middleware);
}
}