|
| 1 | +# Class: RedirectHandler |
| 2 | + |
| 3 | +A class that handles redirection logic for HTTP requests. |
| 4 | + |
| 5 | +## `new RedirectHandler(dispatch, maxRedirections, opts, handler, redirectionLimitReached)` |
| 6 | + |
| 7 | +Arguments: |
| 8 | + |
| 9 | +- **dispatch** `function` - The dispatch function to be called after every retry. |
| 10 | +- **maxRedirections** `number` - Maximum number of redirections allowed. |
| 11 | +- **opts** `object` - Options for handling redirection. |
| 12 | +- **handler** `object` - An object containing handlers for different stages of the request lifecycle. |
| 13 | +- **redirectionLimitReached** `boolean` (default: `false`) - A flag that the implementer can provide to enable or disable the feature. If set to `false`, it indicates that the caller doesn't want to use the feature and prefers the old behavior. |
| 14 | + |
| 15 | +Returns: `RedirectHandler` |
| 16 | + |
| 17 | +### Parameters |
| 18 | + |
| 19 | +- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandlers) => Promise<Dispatch.DispatchResponse>` (required) - Dispatch function to be called after every redirection. |
| 20 | +- **maxRedirections** `number` (required) - Maximum number of redirections allowed. |
| 21 | +- **opts** `object` (required) - Options for handling redirection. |
| 22 | +- **handler** `object` (required) - Handlers for different stages of the request lifecycle. |
| 23 | +- **redirectionLimitReached** `boolean` (default: `false`) - A flag that the implementer can provide to enable or disable the feature. If set to `false`, it indicates that the caller doesn't want to use the feature and prefers the old behavior. |
| 24 | + |
| 25 | +### Properties |
| 26 | + |
| 27 | +- **location** `string` - The current redirection location. |
| 28 | +- **abort** `function` - The abort function. |
| 29 | +- **opts** `object` - The options for handling redirection. |
| 30 | +- **maxRedirections** `number` - Maximum number of redirections allowed. |
| 31 | +- **handler** `object` - Handlers for different stages of the request lifecycle. |
| 32 | +- **history** `Array` - An array representing the history of URLs during redirection. |
| 33 | +- **redirectionLimitReached** `boolean` - Indicates whether the redirection limit has been reached. |
| 34 | + |
| 35 | +### Methods |
| 36 | + |
| 37 | +#### `onConnect(abort)` |
| 38 | + |
| 39 | +Called when the connection is established. |
| 40 | + |
| 41 | +Parameters: |
| 42 | + |
| 43 | +- **abort** `function` - The abort function. |
| 44 | + |
| 45 | +#### `onUpgrade(statusCode, headers, socket)` |
| 46 | + |
| 47 | +Called when an upgrade is requested. |
| 48 | + |
| 49 | +Parameters: |
| 50 | + |
| 51 | +- **statusCode** `number` - The HTTP status code. |
| 52 | +- **headers** `object` - The headers received in the response. |
| 53 | +- **socket** `object` - The socket object. |
| 54 | + |
| 55 | +#### `onError(error)` |
| 56 | + |
| 57 | +Called when an error occurs. |
| 58 | + |
| 59 | +Parameters: |
| 60 | + |
| 61 | +- **error** `Error` - The error that occurred. |
| 62 | + |
| 63 | +#### `onHeaders(statusCode, headers, resume, statusText)` |
| 64 | + |
| 65 | +Called when headers are received. |
| 66 | + |
| 67 | +Parameters: |
| 68 | + |
| 69 | +- **statusCode** `number` - The HTTP status code. |
| 70 | +- **headers** `object` - The headers received in the response. |
| 71 | +- **resume** `function` - The resume function. |
| 72 | +- **statusText** `string` - The status text. |
| 73 | + |
| 74 | +#### `onData(chunk)` |
| 75 | + |
| 76 | +Called when data is received. |
| 77 | + |
| 78 | +Parameters: |
| 79 | + |
| 80 | +- **chunk** `Buffer` - The data chunk received. |
| 81 | + |
| 82 | +#### `onComplete(trailers)` |
| 83 | + |
| 84 | +Called when the request is complete. |
| 85 | + |
| 86 | +Parameters: |
| 87 | + |
| 88 | +- **trailers** `object` - The trailers received. |
| 89 | + |
| 90 | +#### `onBodySent(chunk)` |
| 91 | + |
| 92 | +Called when the request body is sent. |
| 93 | + |
| 94 | +Parameters: |
| 95 | + |
| 96 | +- **chunk** `Buffer` - The chunk of the request body sent. |
0 commit comments