forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new dispatch compose (nodejs#2826)
* feat: add new dispatch compose * fix: review Co-authored-by: Matteo Collina <hello@matteocollina.com> * revert: linting * docs: add documentation * fix: smaller tweaks to proxy interceptor * test: fix tests for proxy * refactor: expose interceptor as is * test: add testing for retry * refactor: rewrite interceptors * refactor: proxy interceptor * feat: redirect interceptor * refactor: change the compose behaviour * docs: update docs * test: add testing for compose * feat: composed dispatcher * docs: adjust documentation * refactor: apply review * docs: tweaks * feat: drop proxy --------- Co-authored-by: Matteo Collina <hello@matteocollina.com>
- Loading branch information
Showing
10 changed files
with
1,418 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
const RedirectHandler = require('../handler/redirect-handler') | ||
|
||
module.exports = opts => { | ||
const globalMaxRedirections = opts?.maxRedirections | ||
return dispatch => { | ||
return function redirectInterceptor (opts, handler) { | ||
const { maxRedirections = globalMaxRedirections, ...baseOpts } = opts | ||
|
||
if (!maxRedirections) { | ||
return dispatch(opts, handler) | ||
} | ||
|
||
const redirectHandler = new RedirectHandler( | ||
dispatch, | ||
maxRedirections, | ||
opts, | ||
handler | ||
) | ||
|
||
return dispatch(baseOpts, redirectHandler) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
const RetryHandler = require('../handler/retry-handler') | ||
|
||
module.exports = globalOpts => { | ||
return dispatch => { | ||
return function retryInterceptor (opts, handler) { | ||
return dispatch( | ||
opts, | ||
new RetryHandler( | ||
{ ...opts, retryOptions: { ...globalOpts, ...opts.retryOptions } }, | ||
{ | ||
handler, | ||
dispatch | ||
} | ||
) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.