Skip to content

Commit

Permalink
refactor: rewrite redirect implementation for agent
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Feb 17, 2024
1 parent 23f24e7 commit c4d7662
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { InvalidArgumentError } = require('./core/errors')
const { kClients, kRunning, kClose, kDestroy, kDispatch } = require('./core/symbols')
const DispatcherBase = require('./dispatcher-base')
const RedirectHandler = require('./handler/RedirectHandler')
const Pool = require('./pool')
const Client = require('./client')
const util = require('./core/util')
Expand Down Expand Up @@ -94,6 +95,18 @@ class Agent extends DispatcherBase {
this[kClients].set(key, dispatcher)
}

if (this[kMaxRedirections] > 0) {
return dispatcher.dispatch(
opts,
new RedirectHandler(
dispatcher.dispatch.bind(dispatcher),
this[kMaxRedirections],
opts,
handler
)
)
}

return dispatcher.dispatch(opts, handler)
}

Expand Down

0 comments on commit c4d7662

Please sign in to comment.