1 | /**
|
2 | * -------------------------------------------------------------------------------------------
|
3 | * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
4 | * See License in the project root for license information.
|
5 | * -------------------------------------------------------------------------------------------
|
6 | */
|
7 | /**
|
8 | * @module RedirectHandler
|
9 | */
|
10 | import { Context } from "../IContext";
|
11 | import { Middleware } from "./IMiddleware";
|
12 | import { RedirectHandlerOptions } from "./options/RedirectHandlerOptions";
|
13 | /**
|
14 | * @class
|
15 | * Class
|
16 | * @implements Middleware
|
17 | * Class representing RedirectHandler
|
18 | */
|
19 | export declare class RedirectHandler implements Middleware {
|
20 | /**
|
21 | * @private
|
22 | * @static
|
23 | * A member holding the array of redirect status codes
|
24 | */
|
25 | private static REDIRECT_STATUS_CODES;
|
26 | /**
|
27 | * @private
|
28 | * @static
|
29 | * A member holding SeeOther status code
|
30 | */
|
31 | private static STATUS_CODE_SEE_OTHER;
|
32 | /**
|
33 | * @private
|
34 | * @static
|
35 | * A member holding the name of the location header
|
36 | */
|
37 | private static LOCATION_HEADER;
|
38 | /**
|
39 | * @private
|
40 | * @static
|
41 | * A member representing the authorization header name
|
42 | */
|
43 | private static AUTHORIZATION_HEADER;
|
44 | /**
|
45 | * @private
|
46 | * @static
|
47 | * A member holding the manual redirect value
|
48 | */
|
49 | private static MANUAL_REDIRECT;
|
50 | /**
|
51 | * @private
|
52 | * A member holding options to customize the handler behavior
|
53 | */
|
54 | private options;
|
55 | /**
|
56 | * @private
|
57 | * A member to hold next middleware in the middleware chain
|
58 | */
|
59 | private nextMiddleware;
|
60 | /**
|
61 | * @public
|
62 | * @constructor
|
63 | * To create an instance of RedirectHandler
|
64 | * @param {RedirectHandlerOptions} [options = new RedirectHandlerOptions()] - The redirect handler options instance
|
65 | * @returns An instance of RedirectHandler
|
66 | */
|
67 | constructor(options?: RedirectHandlerOptions);
|
68 | /**
|
69 | * @private
|
70 | * To check whether the response has the redirect status code or not
|
71 | * @param {Response} response - The response object
|
72 | * boolean representing whether the response contains the redirect status code or not
A |
73 | */
|
74 | private isRedirect;
|
75 | /**
|
76 | * @private
|
77 | * To check whether the response has location header or not
|
78 | * @param {Response} response - The response object
|
79 | * @returns A boolean representing the whether the response has location header or not
|
80 | */
|
81 | private hasLocationHeader;
|
82 | /**
|
83 | * @private
|
84 | * To get the redirect url from location header in response object
|
85 | * @param {Response} response - The response object
|
86 | * @returns A redirect url from location header
|
87 | */
|
88 | private getLocationHeader;
|
89 | /**
|
90 | * @private
|
91 | * To check whether the given url is a relative url or not
|
92 | * @param {string} url - The url string value
|
93 | * @returns A boolean representing whether the given url is a relative url or not
|
94 | */
|
95 | private isRelativeURL;
|
96 | /**
|
97 | * @private
|
98 | * To check whether the authorization header in the request should be dropped for consequent redirected requests
|
99 | * @param {string} requestUrl - The request url value
|
100 | * @param {string} redirectUrl - The redirect url value
|
101 | * @returns A boolean representing whether the authorization header in the request should be dropped for consequent redirected requests
|
102 | */
|
103 | private shouldDropAuthorizationHeader;
|
104 | /**
|
105 | * @private
|
106 | * @async
|
107 | * To update a request url with the redirect url
|
108 | * @param {string} redirectUrl - The redirect url value
|
109 | * @param {Context} context - The context object value
|
110 | * @returns Nothing
|
111 | */
|
112 | private updateRequestUrl;
|
113 | /**
|
114 | * @private
|
115 | * To get the options for execution of the middleware
|
116 | * @param {Context} context - The context object
|
117 | * @returns A options for middleware execution
|
118 | */
|
119 | private getOptions;
|
120 | /**
|
121 | * @private
|
122 | * @async
|
123 | * To execute the next middleware and to handle in case of redirect response returned by the server
|
124 | * @param {Context} context - The context object
|
125 | * @param {number} redirectCount - The redirect count value
|
126 | * @param {RedirectHandlerOptions} options - The redirect handler options instance
|
127 | * @returns A promise that resolves to nothing
|
128 | */
|
129 | private executeWithRedirect;
|
130 | /**
|
131 | * @public
|
132 | * @async
|
133 | * To execute the current middleware
|
134 | * @param {Context} context - The context object of the request
|
135 | * @returns A Promise that resolves to nothing
|
136 | */
|
137 | execute(context: Context): Promise<void>;
|
138 | /**
|
139 | * @public
|
140 | * To set the next middleware in the chain
|
141 | * @param {Middleware} next - The middleware instance
|
142 | * @returns Nothing
|
143 | */
|
144 | setNext(next: Middleware): void;
|
145 | }
|