undici
Version:
An HTTP/1.1 client, written from scratch for Node.js
22 lines (16 loc) • 717 B
JavaScript
const RedirectHandler = require('../handler/redirect-handler')
function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections } = {}) {
return (dispatch) => {
return function Intercept (opts, handler) {
const { maxRedirections = defaultMaxRedirections, ...rest } = opts
if (maxRedirections == null || maxRedirections === 0) {
return dispatch(opts, handler)
}
const dispatchOpts = { ...rest } // Stop sub dispatcher from also redirecting.
const redirectHandler = new RedirectHandler(dispatch, maxRedirections, dispatchOpts, handler)
return dispatch(dispatchOpts, redirectHandler)
}
}
}
module.exports = createRedirectInterceptor