-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathHTTPMessageHandler.ts
More file actions
49 lines (44 loc) · 1.31 KB
/
HTTPMessageHandler.ts
File metadata and controls
49 lines (44 loc) · 1.31 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
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module HTTPMessageHandler
*/
import { Context } from "../IContext";
import { Middleware } from "./IMiddleware";
/**
* @class
* @implements Middleware
* Class for HTTPMessageHandler
*/
export class HTTPMessageHandler implements Middleware {
/**
* @private
* A member to hold next middleware in the middleware chain
*/
private nextMiddleware?: Middleware;
/**
* @public
* @async
* To execute the current middleware
* @param {Context} context - The request context object
* @returns A promise that resolves to nothing
*/
public async execute(context: Context): Promise<void> {
context.response = await fetch(context.request, context.options);
if (!this.nextMiddleware) return;
return await this.nextMiddleware.execute(context);
}
/**
* @public
* To set the next middleware in the chain
* @param {Middleware} next - The middleware instance
* @returns Nothing
*/
public setNext(next: Middleware): void {
this.nextMiddleware = next;
}
}