@nxtedition/nxt-undici 2.0.10 → 2.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/interceptor/redirect.js +14 -15
- package/package.json +1 -1
|
@@ -42,21 +42,17 @@ class Handler {
|
|
|
42
42
|
|
|
43
43
|
this.count += 1
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (this.count >= maxCount) {
|
|
57
|
-
// TODO (perf): Consume body?
|
|
58
|
-
throw new Error(`Max redirections reached: ${maxCount}.`)
|
|
59
|
-
}
|
|
45
|
+
// TODO (feat): follow as function...
|
|
46
|
+
|
|
47
|
+
const maxCount = Number.isFinite(this.opts.follow)
|
|
48
|
+
? this.opts.follow
|
|
49
|
+
: Number.isFinite(this.opts.follow?.count)
|
|
50
|
+
? this.opts.follow?.count
|
|
51
|
+
: 0
|
|
52
|
+
|
|
53
|
+
if (this.count >= maxCount) {
|
|
54
|
+
// TODO (perf): Consume body?
|
|
55
|
+
throw new Error(`Max redirections reached: ${maxCount}.`)
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
if (isDisturbed(this.opts.body)) {
|
|
@@ -83,6 +79,8 @@ class Handler {
|
|
|
83
79
|
origin,
|
|
84
80
|
}
|
|
85
81
|
|
|
82
|
+
this.opts.logger?.debug({ location }, 'following redirect')
|
|
83
|
+
|
|
86
84
|
// https://tools.ietf.org/html/rfc7231#section-6.4.4
|
|
87
85
|
// In case of HTTP 303, always replace method to be either HEAD or GET
|
|
88
86
|
if (statusCode === 303 && this.redirectOpts.method !== 'HEAD') {
|
|
@@ -132,6 +130,7 @@ class Handler {
|
|
|
132
130
|
count: this.count,
|
|
133
131
|
}),
|
|
134
132
|
)
|
|
133
|
+
this.handler = null
|
|
135
134
|
} else {
|
|
136
135
|
return this.handler.onComplete(trailers)
|
|
137
136
|
}
|